1. new libraries to access serial ports
- Posted by jacques_desch May 25, 2009
- 3163 views
For those who maybe interested
I written 2 libraries to access serial port
one for windows: http://www.rapideuphoria.com/serial2.zip
one for linux: http://www.rapideuphoria.com/serial.tar.gz
Jacques
2. Re: new libraries to access serial ports
- Posted by oguim Jul 04, 2009
- 3036 views
Hi I tried to use the libraries , with Eu3.11 installed using EU31setup.exe.
Using the IDE, for a button that calls the comm config dialog, the dialog is called fine, but if that button is colored,as soon as I click on an entry, the program crashes with a popup window with caption "Win32lib App window-Error warning
captureMouse:SetCapture failure , press Yes to continue, no to ignore repeats, and cancel to quit. Win 32lib is version 0.70.4.
If the button that calls the config dialog is not collored, the dialog seems to work fine, but after applying and okeing the changes, nothing seems to change on the serial port settings....
This happens in two different pcs..
Any idea of what may be causing this?
Thank you in advance.
Oguim
3. Re: new libraries to access serial ports
- Posted by ryanj Jul 04, 2009
- 3058 views
For those who maybe interested
I written 2 libraries to access serial port
one for windows: http://www.rapideuphoria.com/serial2.zip
one for linux: http://www.rapideuphoria.com/serial.tar.gz
Jacques
Thank you, Jacques! I have been waiting for someone to write serial libraries for euphoria, especially for linux. Some people seem to think serial ports are obsolete, but that's not true. Those of us who tinker with electronics need serial I/O to talk to micro-controllers, GPS, etc.
I will try your libraries soon.
4. Re: new libraries to access serial ports
- Posted by jacques_desch Jul 04, 2009
- 3083 views
You're using win32lib, I can't help you I never used win32lib, I don't know it.
I think your problem is with Win32lib.
The serial.e library have it own procedure to display serial port configuration dialog. Did you try CommConfigDialag()?
Jacques
Hi I tried to use the libraries , with Eu3.11 installed using EU31setup.exe.
Using the IDE, for a button that calls the comm config dialog, the dialog is called fine, but if that button is colored,as soon as I click on an entry, the program crashes with a popup window with caption "Win32lib App window-Error warning
captureMouse:SetCapture failure , press Yes to continue, no to ignore repeats, and cancel to quit. Win 32lib is version 0.70.4.
If the button that calls the config dialog is not collored, the dialog seems to work fine, but after applying and okeing the changes, nothing seems to change on the serial port settings....
This happens in two different pcs..
Any idea of what may be causing this?
Thank you in advance.
Oguim
5. Re: new libraries to access serial ports
- Posted by oguim Jul 04, 2009
- 3009 views
Thank you for your prompt answer.
Yes, I tried to use comm config dialog, called by a button. It seems to work, cause the dialog opens...it seems to take the changes to the baud rate, bytes, etc...but when I call it again ,the configuration stays as it was before.... I tried to check by the mode com1 on the command line...also shows no changes...
will you please send me a sample of the simplest program that uses the serial port, so I can check if I am doing something stupid?
Thank you.
6. Re: new libraries to access serial ports
- Posted by jacques_desch Jul 06, 2009
- 3081 views
Sorry oguim for late answer.
Thanks for reporting this problem, I tested CommConfigDialog() and as you report it doesn't work.
I read the following on MSDN http://msdn.microsoft.com/en-us/library/aa363187%28VS.85%29.aspx
Remarks
The CommConfigDialog function requires a dynamic-link library (DLL) provided by the communications hardware vendor.
I didn't pay attention to it before.
You should use SetCommState() instead.
integer hComm procedure init_comm(integer comm_port,sequence comm_params) hComm = serial_open(comm_port) if hComm = -1 then puts(1,"serial_open failed\n") abort(1) end if SetCommState(hComm,comm_params) SetCommTimeouts(hComm,{1000,1000,10,1,1}) PurgeComm(hComm,PURGE_TXCLEAR+PURGE_RXCLEAR) end procedure init_comm(4,"baud:19200;parity:none;stop:1;control:none")
jacques
Thank you for your prompt answer.
Yes, I tried to use comm config dialog, called by a button. It seems to work, cause the dialog opens...it seems to take the changes to the baud rate, bytes, etc...but when I call it again ,the configuration stays as it was before.... I tried to check by the mode com1 on the command line...also shows no changes...
will you please send me a sample of the simplest program that uses the serial port, so I can check if I am doing something stupid?
Thank you.
7. Re: new libraries to access serial ports
- Posted by daduko Jul 09, 2009
- 3015 views
Is it possible to turn on/off DTR, DSR signals ?
Vlado
8. Re: new libraries to access serial ports
- Posted by daduko Jul 09, 2009
- 3015 views
EscapeCommFunction(hComm, SETRTS)
9. Re: new libraries to access serial ports
- Posted by jacques_desch Jul 09, 2009
- 3043 views
Is it possible to turn on/off DTR, DSR signals ?
Vlado
The flow contol is set by SetCommState() usiing control parameter
-- no flow control SetCommState(hComm, "baud:9600,parity:even,bits:8,stop:1,control:none") -- software flow control (xon/xoff) SetCommState(hComm, "baud:9600,parity:even,bits:8,stop:1,control:soft") -- hardware flow control DTR/RTS handshake, CTS and DSR are monitored. SetCommState(hComm, "baud:9600,parity:even,bits:8,stop:1,control:hard")
NOTE from: http://msdn.microsoft.com/en-us/library/aa363214(VS.85).aspx
Enables RTS handshaking. The driver raises the RTS line when the "type-ahead" (input) buffer is less than one-half full and lowers the RTS line when the buffer is more than three-quarters full. If handshaking is enabled, it is an error for the application to adjust the line by using the EscapeCommFunction function.
jacques
10. Re: new libraries to access serial ports
- Posted by oguim Dec 15, 2009
- 2901 views
Sir: I saw your message of appologies, but that was not a problem at all, because I had to stay away for about the same time. I followed your suggestion of using SetCommState and it works fine!
Je vous remercie beaucoup!
All the best!
11. Re: new libraries to access serial ports
- Posted by lpuster Oct 19, 2010
- 2635 views
Your library works well for me, except for one thing: If I try to read the input stream when there are no bytes in the buffer, the whole computer locks up waiting for data.
How can I test to see if the input buffer is empty or not?
There must be a way to do it, as every terminal program waits for input and displays it whenever it comes without locking up. Can I hook into the serial port interrupt chain?
12. Re: new libraries to access serial ports
- Posted by coconut Oct 19, 2010
- 2588 views
Your library works well for me, except for one thing: If I try to read the input stream when there are no bytes in the buffer, the whole computer locks up waiting for data.
How can I test to see if the input buffer is empty or not?
There must be a way to do it, as every terminal program waits for input and displays it whenever it comes without locking up. Can I hook into the serial port interrupt chain?
Hi! lpuster,
Both libraries, the windows version and the linux version, have provision for timing out. I didn't used that code for over 1 year so I don't remember the details, but I'm sure you can read the source code as well as me.
regards, Jacques d.
13. Re: new libraries to access serial ports
- Posted by Fernando Oct 19, 2010
- 2586 views
Your library works well for me, except for one thing: If I try to read the input stream when there are no bytes in the buffer, the whole computer locks up waiting for data.
How can I test to see if the input buffer is empty or not?
There must be a way to do it, as every terminal program waits for input and displays it whenever it comes without locking up. Can I hook into the serial port interrupt chain?
Hi! lpuster,
Both libraries, the windows version and the linux version, have provision for timing out. I didn't used that code for over 1 year so I don't remember the details, but I'm sure you can read the source code as well as me.
regards, Jacques d.
Hi,
Thanks Jacques for your library. I have been using it with success to test some devices.
Maybe this could help (tested in Windows XP):
include serial.ew include get.e include misc.e object val integer port, a atom hCom1 constant MAXDWORD=#FFFFFFFF constant ESC=27 port = 1 -- ADJUST TO YOUR PORT hCom1 = serial_open(port) if hCom1 < 0 then printf(1,"Error opening port %d.\n\n",port) abort(1) end if -- http://msdn.microsoft.com/en-us/library/aa363190%28v=VS.85%29.aspx -- A value of MAXDWORD, combined with zero values for both the ReadTotalTimeoutConstant and ReadTotalTimeoutMultiplier members, -- specifies that the read operation is to return immediately with the bytes that have already been received, -- even if no bytes have been received. SetCommTimeouts(hCom1,{MAXDWORD,0,0,0,0}) SetCommState(hCom1, "baud:9600;parity:none;bits:8;stop:1;control:none") puts(1,"1) Connect TX and RX (loopback) (pins 2 and 3 in the DB9 connector).\n" & "2) Every key you hit will be send and received by serial port and echoed to the screen.\n" & "3) ESC abort.\n") PurgeComm(hCom1,PURGE_RXCLEAR) while 1 do a = get_key() if a != -1 then if a = ESC then puts(1,"\nAborted!\n") abort(0) end if serial_puts(hCom1, a) -- SEND KEY CODE TO SERIAL PORT end if val = serial_getc(hCom1) if val != -1 then puts(1,val) end if end while
P.S.: I had to define MAXDWORD since it's not defined as global in serial.ew.
Regards,
Fernando
14. Re: new libraries to access serial ports
- Posted by useless Oct 19, 2010
- 2588 views
Have you tested and debugged it with a usb port?
useless
15. Re: new libraries to access serial ports
- Posted by coconut Oct 20, 2010
- 2462 views
Have you tested and debugged it with a usb port?
useless
Yes both on windows xp sp3 and linux I used it with USB-RS232 converter sucessfully. As long as the driver for the converter is installed and functionnal, for application programming this like any other serial port.
But I didn't test the libraries extensively. I written those libraries for a personnal project and as long as it works with my project I'm satisfied with it. As it was written I decided to share it but I don't intent to support it. Use it as it is, or debug and improve it by yourself.
Regards, Jacques
16. Re: new libraries to access serial ports
- Posted by Fernando Oct 20, 2010
- 2481 views
Have you tested and debugged it with a usb port?
useless
Yes. I can confirm that the library and the code I posted works with virtual COM ports (tested with the bridge PL-2303HXD).
- Fernando
17. Re: new libraries to access serial ports
- Posted by coconut Oct 21, 2010
- 2366 views
Have you tested and debugged it with a usb port?
useless
Yes. I can confirm that the library and the code I posted works with virtual COM ports (tested with the bridge PL-2303HXD).
- Fernando
Hi Fernando, If you look at the first message of that thread, it is about my serial librairies posted to rds 1 year ago.
regards, Jacques
18. Re: new libraries to access serial ports
- Posted by Fernando Oct 22, 2010
- 2301 views
Have you tested and debugged it with a usb port?
useless
Yes. I can confirm that the library and the code I posted works with virtual COM ports (tested with the bridge PL-2303HXD).
- Fernando
Hi Fernando, If you look at the first message of that thread, it is about my serial librairies posted to rds 1 year ago.
regards, Jacques
Hi Jacques,
Yes, I know that. Thanks again. I have been using it since January/2010. Maybe I didn't understand your last reply (?).
Regards,
Fernando