|
Post by stan58 on Sept 19, 2019 4:30:12 GMT -5
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?
|
|
|
Post by Brandon Parker on Sept 20, 2019 18:19:26 GMT -5
I would output the data to a CSV file for use in excel. Outputting to a basic CSV format is pretty straight forward.
{:0)
Brandon Parker
|
|
|
Post by stan58 on Sept 25, 2019 4:52:02 GMT -5
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.
|
|
|
Post by Rod on Sept 25, 2019 6:38:06 GMT -5
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.
|
|
|
Post by metro on Sept 25, 2019 8:38:00 GMT -5
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
End
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
|
|
|
Post by Brandon Parker on Sept 25, 2019 19:33:15 GMT -5
Have you attempted to just keep all of the data in your "in-house" application? You can use a ListView to display all of the values similar to Excel, and then you can roll your own graphing functionality. This can be easier than it might seem. The attachment shows both ... programmed in Liberty BASIC with the help of API stuff for the ListView. {:0) Brandon Parker Attachments:
|
|
|
Post by stan58 on Sept 26, 2019 15:02:48 GMT -5
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.
|
|
|
Post by tsh73 on Sept 26, 2019 15:53:53 GMT -5
(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.
|
|
|
Post by Rod on Sept 27, 2019 3:19:59 GMT -5
Trying to write a “listview” with spreadsheet capabilities in Liberty would be quite complex.
We are offering solutions without understanding the problem.
Writing code to draw fancy charts and four wheel balance diagrams is easy by comparison.
So are you wanting a flexible charting system (hard work), or fixed format charting , (easy)
|
|
|
Post by stan58 on Oct 1, 2019 5:46:14 GMT -5
Rod Fixed format I just have two vectors time and weight , user sets the time base IE 5 seconds then I store the time and weight every 5 seconds.
|
|
|
Post by Rod on Oct 1, 2019 9:36:11 GMT -5
Ok, this is how simple it is to display a line chart and allow the user to alter the sampling time.
nomainwin
dim tick$(5) tick$(1)="1" tick$(2)="5" tick$(3)="10" tick$(4)="30" tick$(5)="60" 'default freq 1*1000ms tick=1000
' open our window and graphicsbox and set options and event labels
WindowWidth = 600 WindowHeight = 600 UpperLeftX = (DisplayWidth-WindowWidth)/2 UpperLeftY = (DisplayHeight-WindowHeight)/2 statictext #1.t,"Sample (Sec)",50,380,100,20 graphicbox #1.g, 50,80,500,300 combobox #1.timing,tick$(),[tickchange],50,400,100,20 open "Graph" for graphics_nf_nsb as #1 #1 "trapclose [quit]" #1.g "down" #1.timing "selectindex 1"
' fancy shaded graphics you could equally down ; fill black for y= 300 to 0 step -2 print #1.g, "color ";y/2+100;" ";y/2+100;" ";y/2+100 print #1.g, "line 0 ";y;" ";"500 ";y print #1.g, "line 0 ";y-1;" ";"500 ";y-1 next y print #1.g, "color yellow" print #1.g, "line 0 150 500 150" print #1.g, "flush" print #1.g, "getbmp bmp 0 0 500 300" oldpos=0 oldv=0
'start sampling at the default freq timer tick, [graphit] wait
'this is polled at the set freq, you would seek your sample [graphit] pos=pos+1
' calculate a new random value for demo purposes #1.g, "color red " v=200-rnd(0)*100
'draw a very simple line chart #1.g,"line ";oldpos;" ";oldv;" ";pos;" ";v oldpos=pos oldv=v
' wait for the next timer or keyboard event wait
[tickchange] timer 0 #1.timing "selection? t$" tick=1000*val(t$) timer tick, [graphit] wait
[quit] timer 0 close #1 end
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.
|
|
|
Post by Brandon Parker on Oct 2, 2019 19:25:33 GMT -5
... And ... here is a link to a post which includes code that I gave to Metro a while back for some ListView stuff. Simple ListView Stuff{:0) Brandon Parker
|
|