Page 1 of 1
Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 5:40 am
by John-G
Here is a little code that i made up. What am i doing wrong here .. ( just testing so dont yell to much )
It is just a little Example that I am showing just to see how the rs232 works
it opens the Com no problem, the sends a FA; Sending that command to answer what Freq it is on
then "Result = AvailableSerialPortInput(1)" result always reads 0 ( I should get 14 ) to show nothing to get
If i run a rs232 Port Monitor i see:
" 46 41 30 30 30 35 30 31 34 30 31 38 30 3B FA00050140180;"
but if i start Hyper-Terminal and set the com the same way i get the answer back that was setting in the buffer?
" FA00050140180; "
I have played with this for 2 days and i cant see what i am doing wrong
Code: Select all
Define.l read_amount, incoming = AllocateMemory(1024)
If OpenSerialPort(1, "COM1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
MessageRequester("Information", "SerialPort opened with success")
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
EndIf
Delay(1000)
WriteSerialPortString(1, "FA;")
Delay(1000)
Result = AvailableSerialPortInput(1)
Delay(1000)
Debug Result
Delay(1000)
For a = 1 To Result
read_amount = ReadSerialPortData(1, incoming, Length)
Delay(1000)
Debug PeekS(incoming, read_amount)
Next a
End
Thanks John_G
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 6:33 am
by KGB_X
is it a Kenwood you are trying to "talk" to? If so what model?
If the "AI" command is on then you are probably getting other data.
So first try to send "AI0;" to turn off auto information. I think you also have to read until you get a linefeed.
Now you are sure that the only data coming from your radio is when you have issued a request.
73 de LA3QMA
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 6:41 am
by John-G
It is a Kenwood ts-2000x and a AI0 is ok but i can read it with Hyper-Terminal with no problem .. I can live with what i get for now .. just get it to read i will be happy.. N3ovo
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:10 am
by John-G
KGB_X wrote:is it a Kenwood you are trying to "talk" to? If so what model?
If the "AI" command is on then you are probably getting other data.
So first try to send "AI0;" to turn off auto information. I think you also have to read until you get a linefeed.
Now you are sure that the only data coming from your radio is when you have issued a request.
73 de LA3QMA
no good i tryed it .. i and sent commands and turn on the radio i just can read from it .. here is what i tried again. it turn on the radio but no info back. then opened up Hyper-Terminal and again i got want i needed .... hummmmmm :roll:
Code: Select all
; Syntax
; Result = OpenSerialPort(#SerialPort, SerialPortName$, Bauds, Parity, Data, Stop, HandshakeMode, InputBufferSize, OutputBufferSize)
If OpenSerialPort(0, "COM1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Define.l is_there_data_to_read, read_amount
Define.l timeout_now, timeout_max = 5000
Define.l incoming = AllocateMemory(1024)
If incoming
Delay(5)
WriteSerialPortString(0, "PS1;")
Delay(500)
WriteSerialPortString(0, "PS1;")
Delay(10000)
WriteSerialPortString(0, "AI0;")
WriteSerialPortString(0, "FA;")
WriteSerialPortString(0, "AI0;")
Repeat
Delay(10) : timeout_now + 10
is_there_data_to_read = AvailableSerialPortInput(0)
Until is_there_data_to_read Or (timeout_now => timeout_max)
If is_there_data_to_read
read_amount = ReadSerialPortData(0, incoming, Length)
Debug PeekS(incoming, read_amount)
Else
Debug "timeout reached / no data to read"
EndIf
FreeMemory(incoming)
EndIf
Else
Debug "couldn't open com"
EndIf
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:13 am
by KGB_X
ahh so you dont get a response...
This should work as i just tested it on my TS2k
Code: Select all
Define.l read_amount, incoming = AllocateMemory(1024)
;If OpenSerialPort(1, "/dev/ttyS1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
If OpenSerialPort(1, "COM1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Debug "serialport opened ok"
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
End
EndIf
If IsSerialPort(1)
result=WriteSerialPortString(1, "FA;"+Chr(13))
Delay(100)
x=AvailableSerialPortInput(1)
Text2.s =""
Buffer$=""
While AvailableSerialPortInput(1)>0
If ReadSerialPortData(1, @Buffer, 1) ; Read Byte
Text2.s = Text2.s + Chr(Buffer)
EndIf
Wend
result$ = Mid(RemoveString(Text2.s,Chr(13)),4)
Debug result$
Else
Debug "ERROR"
EndIf
End
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:14 am
by KGB_X
you need to enter a CHR(13) after the commands..
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:43 am
by John-G
Hummm ok the port opens but nothing ... hummmmm thanks for the help any thoughts?
KGB_X wrote:ahh so you dont get a response...
This should work as i just tested it on my TS2k
Code: Select all
Define.l read_amount, incoming = AllocateMemory(1024)
;If OpenSerialPort(1, "/dev/ttyS1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
If OpenSerialPort(1, "COM1", 9600, #PB_SerialPort_NoParity, 8, 1, #PB_SerialPort_NoHandshake, 1024, 1024)
Debug "serialport opened ok"
Else
MessageRequester("Error", "Can't open the serial port: "+Port$)
End
EndIf
If IsSerialPort(1)
result=WriteSerialPortString(1, "FA;"+Chr(13))
Delay(100)
x=AvailableSerialPortInput(1)
Text2.s =""
Buffer$=""
While AvailableSerialPortInput(1)>0
If ReadSerialPortData(1, @Buffer, 1) ; Read Byte
Text2.s = Text2.s + Chr(Buffer)
EndIf
Wend
result$ = Mid(RemoveString(Text2.s,Chr(13)),4)
Debug result$
Else
Debug "ERROR"
EndIf
End
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:52 am
by KGB_X
check that DTR and RTS are correct if not you wont receive anything..
i'm back on sunday but you have probably solved the problem before that time...
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 7:59 am
by John-G
Ok i put a break point at the bottom ( the Last Endif ) and the looked at
x=AvailableSerialPortInput(1) and got a 0 for input
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 8:02 am
by John-G
KGB_X wrote:check that DTR and RTS are correct if not you wont receive anything..
i'm back on sunday but you have probably solved the problem before that time...
I dont know about getting to work .. but thanks for you help i added this to your code
Delay(5)
WriteSerialPortString(1, "PS1;")
Delay(500)
WriteSerialPortString(1, "PS1;")
Delay(10000)
then turned it off and watch it turn on and work so ... Still stuck but still working on it .. thanks again for your help
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 8:22 am
by KGB_X
You dont need all the delays.
Kenwood radios are within 100ms
try this before sending commands:
Code: Select all
SetSerialPortStatus(sid,#PB_SerialPort_RTS,1|2)
Delay(100)
SetSerialPortStatus(sid,#PB_SerialPort_DTR,0)
Delay(100)
SetSerialPortStatus(sid,#PB_SerialPort_TXD,0)
Re: Sending and Receiveing problems - RS232
Posted: Sat Oct 17, 2009 8:33 am
by John-G
you are the Best ... thanks thanks thanks thanks thanks .. it is working .. i can get it from here .. Some day i hope i can help you on somthing
Re: Sending and Receiveing problems - RS232
Posted: Mon Oct 19, 2009 5:13 pm
by KGB_X
hehe no problem... took me some time to control my TM-D700 when i first started using PureBasic.