Serial Port
Hello everyone, i'm writing a small c program, but i have stucked .
I have connected a small device on serial port, when i send a "9G" command to a device he's respond is "9G12,22;". This perfectly works in minicom. Parameters: 9600 8N1 NO HARDWARE FLOW CONTROL NO SOFTWARE FLOW CONTROL /dev/ttyS0 /dev/ttS0 is accessible, because i did chmod a+rw /dev/ttyS0 The same response i'm trying to achieve with my code, but i got no response:( I think there is an error in serial port parameters settings in code. Please HEEELP: Code:
|
// something went wrong during the posting :(
|
First thing I notice is that what you send in minicom is not the same as what you send in your program.
In minicom, you only send 2 characters (or 3 or 4 including a CR and/or LF). In your program however you send 2 and a string terminator. I think that your device needs a CR and/or LF to see the end of the command, so I would change Code:
n=write(fd,"9G",3); Code:
n=write(fd,"9G\n",3); If your PC has 2 serial ports, you can connect them, run minicom on the one and your program on the other. If you don't have 2 serial ports, you can use pseudo terminals. Start minicom as below and change /dev/ttyS0 in your program to /dev/ttyp0. minicom -o -p /dev/ptyp0 Both allow you to check in minicom what you're sending and send replies back and check what your program is reading. Info about pseudo terminals can be found on http://www.tldp.org/HOWTO/Text-Terminal-HOWTO-6.html Below my code for a serial port setup. It also check if some of the parameters are set after a tcsetattr. Code:
#define RS232PARAM (ird->comms.rs232) |
All times are GMT -5. The time now is 04:15 PM. |