I can import serial data from a com port and store it into a user selected a file, I would also like the option to flow it into the page in focus I.E. an Excel spreadsheet. I think this is called a wedge programme. Any tips?
Thank you Brandon My programmes have the feature that you describe of storing the data from the weighing indicator to a user named file in CSV format. But I wondered if the data could be sent directly into an opened document?. Some users seem to want this option.
With you help I have a pretty good number of apps for interfacing to our weighing indicators, if you google electronicweighing.co.uk you can see my Liberty basic Applications . LB is a remarkable platform for novices to create apps however I would be ashamed to publish my spaghetti code! I use "Install creator" to distribute to client. I don't charge for the software but it helps to sell our product.
There are a few options to explore but none are simple solutions. 1) Liberty can use the sendkey() API to mimic keyboard input. The spreadsheet needs to have focus and be awaiting keyboard input. 2) You can write a macro in Excel to keep reading the contents of a file. Liberty simply updates the file, that way data streams at Excel. How file open conflicts are handled would be the tricky part.
There were sendkey() examples on the old forum but I have no code on file. There is also code to create and share environment variables between programs on the LBPE but I would not know if Excel can read environment variables easily.
Perhaps the Excel community would have better advice for you.
The only reference to Sending Keystrokes to another Application (notepad) that I can find on the old forum is code Janet posted July 2008 not sure if it fits your purpose I had to rem out the paint references as I am using Linux and only have notepad installed
Global AppHandle, hName$, hFocus ' Make sure the program is running Run "Notepad.exe"
' Loop to be sure you have the correct handle While Instr(hName$, "Notepad") = 0 Scan ' Get the handle of the window in the Foreground CallDll #user32, "GetForegroundWindow", hFocus as uLong Callback address, enumWndProc(uLong, uLong), Boolean CallDLL #user32, "EnumWindows", _ address as uLong, _ 0 as Long, _ result as Boolean ' Sleep to minimize CPU usage within the loop CallDLL #kernel32, "Sleep", 500 as uLong, result as Void ' Check again for the presence of Notepad is in the forefront Wend ' Now you have the handle of Notepad noteHandle = hFocus Print Print "The handle of Notepad is ";noteHandle
' Is this true? Run MS Paint, wait 3 seconds, then return focus to Notepad Run "MSPaint.exe" CallDLL #kernel32, "Sleep", 3000 as uLong, result as Void CallDLL #user32,"SetForegroundWindow", noteHandle as uLong, result as Boolean CallDLL #user32, "SetActiveWindow", noteHandle as uLong, result as Void
' Okay, so now we know it's possible to interact with another program. ' Can you send data? Give a little time for Notepad to gain focus CallDLL #kernel32, "Sleep", 3000 as uLong, result as Void ' Then type with keybd_event txt$ = "jcby" For i = 1 to Len(txt$) n = Asc(Mid$(txt$, i, 1)) If n > 96 Then If n < 123 Then n = n - 32 End If End If Call KeyboardClick n, 0 Call KeyboardClick n, 2 Next i Call KeyboardClick _VK_RETURN, 0 Call KeyboardClick _VK_RETURN, 2 Call KeyboardClick _VK_TAB, 0 Call KeyboardClick _VK_TAB, 2 txt$ = "is using Liberty BASIC." For i = 1 to Len(txt$) shift = 0 n = Asc(Mid$(txt$, i, 1)) If n > 64 Then If n < 91 Then shift = 1 End If End If If n > 96 Then If n < 123 Then n = n - 32 End If End If If shift = 1 Then Call KeyboardClick, _VK_SHIFT, 0 End If Call KeyboardClick n, 0 Call KeyboardClick, n, 2 If shift = 1 Then Call KeyboardClick, _VK_SHIFT, 2 End If Next i Call KeyboardClick _VK_RETURN, 0 Call KeyboardClick _VK_RETURN, 2
Sub KeyboardClick n, pos ' Need a little time in between keypresses CallDLL #kernel32, "Sleep", 100 as uLong, result as Void ' pos 0 = Down, 2 = Up CallDLL #user32, "keybd_event", _ n as Long, _ null as Long, _ pos as Long, _ result as Void End Sub
Function enumWndProc(handle, lparam) labelBuffer$ = Space$(200) CallDLL #user32, "GetWindowTextA", _ handle as uLong, _ labelBuffer$ as Ptr, _ 70 as Long, _ result as Long
If handle = hFocus Then AppHandle = handle hName$=labelBuffer$ enumWndProc = 0 Print "Window: ";AppHandle;" - ";hName$ Else AppHandle= 999999 enumWndProc = 1 End If End Function
Thanks for the information . I shall forget the keyboard wedge idea but can you explain the "list view" a bit more. as this appears to be easier for the user if I can display the graph without the user having to use the Excel formula. Otherwise as I keep the two graph axis in adjacent columns, is it possible for me to include the formula at the end of the file so that after the CSV file is opened with an Excel sheet the graph is automatically included.
Otherwise as I keep the two graph axis in adjacent columns, is it possible for me to include the formula at the end of the file so that after the CSV file is opened with an Excel sheet the graph is automatically included.
(IMHO) you actually can include formula in CSV as "=someExcelFormula" (used to work for me) but you cannot include graph in CSV.
Though you can write macro in Excel as to how you create it, save that macro to I say personal.xlt (or whatever personal macros book is called now - Google says Personal.xlsb) and then recreate graph by running that macro in Excel.
Now we can add bells and whistles but you need to be very much more verbose about what the chart should look like. Why is it simply weight over time, surely the weight changes moment by moment so sampling may weigh when the scales are empty. But what time scale? an hour? a working day? What weight scale? 1gm 1kg 1 ton? What type of chart line, bar,scatter?
What to do when the time scale has been achieved? print the chart , store the data, store it in a date and time stamped file?
All is possible just the specification needs firmed up.