|
Post by angelo2449 on May 26, 2018 7:58:21 GMT -5
I would like to read a data that sometimes comes on the serial port (bluetooth) so the program must be waiting, how to do?
Thank you
|
|
|
Post by Rod on May 26, 2018 9:53:17 GMT -5
Can you be more specific? Do you mean Bluetooth or a Bluetooth device that mimics an rs232 serial port. Liberty can deal with the latter. There are plenty examples on the LBPE discussing serial port handling. Perhaps if you gave us the name of the device and message examples you would get better help.
Essentially you keep polling the serial port using a timer to see if there is anything in the buffer, if so act on it or wait for the next poll. Its relatively simple to do but too wide ranging a subject to offer code examples.
|
|
|
Post by angelo2449 on May 27, 2018 5:15:21 GMT -5
The device is Leica Disto d110, he measures and sends the string or the value of measurement to bluetooth. I would like to read this, thank you.
|
|
|
Post by Rod on May 27, 2018 14:43:35 GMT -5
Ok, that is a dedicated Bluetooth v4 interface, it is not a rs232 interface. I have not seen any code that interfaces this way.
|
|
|
Post by themendist on Jun 9, 2019 5:28:46 GMT -5
Hi All, Not sure if this is the right place to ask but here goes. I have an old CNC lathe which is currently controlled by DOS software. It works well but the software is a bit slow and tedious to use.
The lathe is controlled using RS323 and I have a list of its control codes. I wrote a simple GUI interface in LB to send these controls to the lathe. When the programme is run and the relevant GUI button pressed the lathe does as requested. If the same button is again pressed nothing happens unless you switch the lathe on an off. It will then do exactly the same, ie receive one message and the lock up.
I know that the lathe sends ASCII codes 13 10 17 when it has received a message but as a new coder I don't know how to get the programme to wait for this reply before moving on.
I am not entirely sure that this is the only problem but at least its a start.
Hope someone can help.
Kind regards.
Keith
|
|
|
Post by Rod on Jun 9, 2019 14:16:11 GMT -5
Does the lathe board have a support page on the web. If not show us an example of sending it a message in Liberty code.
|
|
|
Post by themendist on Jun 11, 2019 5:34:43 GMT -5
Hi Rod, Sadly it does not have any support. Most people have converted it to more modern hardware so that they can use modern software.
print #comm, "park-x" this command Homes the X axis
Print #comm, "zx?" this command asks the lathe for the position of the X and Y axes
After each command the lathe sends a reply "zx?" sent would the receive the reply z01234x1234 and the ascii codes 13 10 17
As I mention in my post the first command works then the lathe returns an error and you cannot send a second command.
Using an RS232 analyser and the original DOS software showed me a list of all the commands sent to the lathe.
Using a freeware terminal program enables me to test the commands and they all seem to work OK.
I am convinced that the problem is in my lack of knowledge of LB.
Many Thanks,
Keith
|
|
|
Post by Rod on Jun 11, 2019 11:08:48 GMT -5
Ok, show us the Liberty code you are using to send and receive a command sequence.
Is the error code documented?
Most of these machines rely on clear text messaging. Done need a check digit or checksum appended to messages so the machine can be sure it has the correct command.
Try and show us a real message asc by asc character and a real response asc by asc character. Use your terminal to capture a real working conversation.
|
|
|
Post by themendist on Jun 11, 2019 12:05:55 GMT -5
Here is the LB code. 'Conect Cadet Plus Manual Control "
nomainwin
WindowWidth = 650 WindowHeight = 475
graphicbox #main.gb, 800, 1, 10, 10 statictext #main.statictext1, "CONECT CADET PLUS CNC LATHE CONTROLLER", 150, 11, 350, 20
button #main.button2, "-X", [button2Click], UL, 110, 226, 26, 25 button #main.button3, "+Z", [button3Click], UL, 150, 266, 26, 25 button #main.button4, "+X", [button4Click], UL, 110, 306, 26, 25 button #main.button5, "-Z", [button5Click], UL, 70, 266, 26, 25 button #main.button6, "Home X", [button6Click], UL, 206, 236, 58, 25 button #main.button7, "Home Z", [button7Click], UL, 206, 291, 58, 25
button #main.button10, "OFF", [button10Click], UL, 454, 301, 34, 25 button #main.button11, "ON", [button11Click], UL, 398, 301, 26, 25 button #main.button12, "+S", [button12Click], UL, 398, 251, 26, 25 button #main.button13, "-S", [button13Click], UL, 454, 251, 26, 25 statictext #main.statictext14, "Spindle", 414, 341, 56, 20 statictext #main.statictext16, "Axis Control", 134, 341, 96, 20 textbox #main.textbox17, 410, 46, 100, 25 'X Pos textbox #main.textbox18, 410, 91, 100, 25 'Z Pos textbox #main.textbox19, 410, 136, 100, 25 ' RPM textbox #main.textbox24, 22, 41, 300, 150 'G Code Box statictext #main.statictext25, "X Pos", 334, 46, 40, 20 statictext #main.statictext26, "Z Pos", 334, 96, 40, 20 statictext #main.statictext27, "RPM=", 334, 141, 40, 20 open "CADET Plus" for window as #main print #main.gb, "when characterInput [getChar]" 'When the user presses a key go to [getChar] print #main, "Trapclose [quit]" print #main, "font courier_new 9"
'SET UP COM PORT
'Set the size of the communications buffer to 16K Com = 8192 * 2
'Open communications port 1. It's handle is #comm.
'If you need to change to com 1, this is the line to modify
open "COM2:9600,e,7,1," for random as #comm
timer 125, [bufferread] wait [bufferread] If lof(#comm) >= 20 then dataRead$ = input$(#comm, 20)
print #main.textbox24, dataRead$;
end if wait
[getChar]
[main.inputLoop] 'wait here for input event wait
[button2Click] 'Perform action for the button named 'button2'-X 'Insert your own code here
wait
[button3Click] 'Perform action for the button named 'button3'+Z 'Insert your own code here
wait
[button4Click] 'Perform action for the button named 'button4'+X 'Insert your own code here
wait
[button5Click] 'Perform action for the button named 'button5'-Z 'Insert your own code here
wait
[button6Click] 'Perform action for the button named 'button6'Home X 'Insert your own code here print #comm, "park-x "
wait
[button7Click] 'Perform action for the button named 'button7'Home Z 'Insert your own code here print #comm, "park-z"
wait
[bmpbutton8Click] 'Perform action for the bmpbutton named 'bmpbutton8'EStop 'Insert your own code here print #comm, "M21" print #main.textbox24, "Emergency STOP" wait
[button10Click] 'Perform action for the button named 'button10'OFF 'Insert your own code here print #comm, "M05" wait
[button11Click] 'Perform action for the button named 'button11'ON 'Insert your own code here print #comm, "M03S200" wait
[button12Click] 'Perform action for the button named 'button12'+S 'Insert your own code here print #main.textbox19, "1500" wait
[button13Click] 'Perform action for the button named 'button13'-S 'Insert your own code here print #main.textbox19, "500" wait
goto [loop]
[quit]
close #main close #comm end
This is a sample of the original software sending and receiving from the lathe. This software is able to control the lathe manually and send G Code in the automatic mode.
Note (Software: What is the position of X and Z) (Lathe: X= +02725 Z= +06468) _______________________________________ xz? x+02725z+06468 xz?
x+02725z+06468 xz?
xz? xz?
x+02725z+06468 D7990
M04 o}1500
clear
G96S Zv50D7990
G00X0Z6200F1200
xz?
x+02725z+06468G G01X0Z6200F80S2500
xz?
x+000z+06200 G00X10Z6210F1200
xz?
x+000z+06200G G00X-50Z6210F1200
xz?
x+00010z+06210G G01X-50Z582F80S2500
xz?
x-00050z+06210G G01X-25Z582F80S2500
xz?
x-00050z+0582G G00X-25Z6210F1200
xz?
x-00025z+0582G G00X-100Z6210F1200
xz?
x-00025z+06210G G01X-100Z582F80S2500
xz?
x-00100z+06210G G01X-75Z582F80S2500
xz?
x-00100z+0582G G00X-75Z6210F1200
xz?
x-00075z+0582G G00X-150Z6210F1200
xz?
x-00075z+06210G
Thanks for your help. Keith
|
|
|
Post by Rod on Jun 12, 2019 3:19:43 GMT -5
'change this line
open "COM2:9600,e,7,1," for random as #comm
'It is recommended that you set certain handshaking switches 'so that your program doesn't just freeze when waiting for 'data to come in or trying to send data. 'To do this, we add ds0, cs0, and rs switches as below.
open "COM2:9600,n,7,1,ds0,cs0,rs" for random as #comm
Given it handles the first command I am pretty sure it is just handshaking giving you problems.
|
|
|
Post by themendist on Jun 12, 2019 5:32:48 GMT -5
Thanks for your advice,
I tried modifying the line as you suggested but unfortunately the lathe did exactly the same thing, worked once then locked up.
When I was originally trying the lathe on LB I used the TERMINAL programme in the samples directory.
If I typed park-x into the (kb)box then pressed return a small square appeared after the typed words and the lathe homed the x axis. when the axis had reached the home position the a further small square appeared on the next line.
If I the typed park-z into the (kb)box then pressed return a small square appeared after the typed words and the lathe homed the z axis. when the axis had reached the home position the a further small square appeared on the next line.
You could then enter any of the other lathe codes and it would respond when you pressed return.
I have assumed that the small squares are ASCII characters.
Keith
|
|
|
Post by Rod on Jun 12, 2019 7:57:20 GMT -5
Yes ASC characters, unprintable ones. What you need to do is play with the terminal software again. You need to properly understand the conversation you are having with the lathe character by character.
When you get a message back from the lathe it will be stored in a string say a$, now instead of printing a$ what you need to do is find the length of a$ with l=len(a$) then character by character find the ASC values. Use print asc(mid$(a$,1,1)), print asc(mid$(a$,2,1)), print asc(mid$(a$,3,1)) etc right up to the full length of the string you obtained with l=len(a$)
Now you will have the full message and you will know what these hidden characters are. It sounds like you have to wait on the lathe responding prior to sending your next command. It may just be a timing issue.
Also, Liberty always adds a CRLF pair to sent text. To stop that you end your text with a ; that suppresses the CRLF. Your lathe may well ignore these two additional characters but it might be confusing it. Try messaging with and without a trailing ;
print #comm, "park-z";
read the buffer something like this way
[bufferread]
If lof(#comm) >0 then
dataRead$ = input$(#comm,lof(#comm))
l=len(dataRead$)
for n=1 to l
print mid$(dataRead$,n,1),asc(mid$(dataRead$,n,1))
next
|
|
|
Post by themendist on Jun 12, 2019 9:28:10 GMT -5
Hi I have just been out in my workshop testing the lathe with the terminal software.
When you switch on the lathe sends 127 13 10 13 10 17
Park-z sends 112 97 114 107 45 122 19 to the lathe and the reply is 13 10 17
I discovered that the lathe needs ASCII chr$ 13 after the instruction.
Following your last post I tried the line below.
print #comm, "park-x" +chr$ (13);
The LB programme now works every time.
I will now try to write the codes for the other buttons.
Thanks again for your help,
Keith
|
|
|
Post by themendist on Jun 12, 2019 9:51:46 GMT -5
Another question. Is there some code to detect if the CTS line is ON so that I can put a Lathe ON indicator on my control panel?
Keith
|
|
|
Post by Rod on Jun 12, 2019 12:46:21 GMT -5
Cool, it is always a precise conversation.
|
|