gettingstarted
[Top] [All Lists]

Re: Problems Reading and Writing to the Serial Port

To: gettingstarted at lists dot realsoftware dot com
Subject: Re: Problems Reading and Writing to the Serial Port
From: martin dot honeywill at unusual dot co dot uk
Date: 31 Jan 2005 19:11:02 UT
Delivered-to: gettingstarted at lists dot realsoftware dot com
Importance: normal
Priority: normal
Hello again,

Its always the case, you ask for help then find the problem just after you have 
asked.

I cannot do the following

>   serial1.write chrb(&he0)
>   serial1.write chrb(&h8e)
>   serial1.write chrb(&h37)

I was assuming that this was just filling up a transmit buffer, this does not 
seem to be the case. I assume I must use XmitWait between each write. This is 
not made clear in the manuals.

I have changed my code to 

  test = chrb(&he0) + chrb(&h8e) + chrb(&h37) + chrb(&h00) + chrb(&hc5)
  Serial1.write test
  Serial1.XmitWait

And this seems to work :-),

Regards

Martin Honeywill


-------- Original Message --------
Subject: Problems Reading and Writing to the Serial Port (31-Jan-2005 18:09)
From:    martin dot honeywill at unusual dot co dot uk
To:      gettingstarted at lists dot realsoftware dot com

> Hi,
> 
> Help I'm lost trying to use RB's serial port control. I'm a new RB5.5.4 
> user on windows XP. I'm planning to write an application that will use the 
> serial port to communicate via a binary protocol on a half duplex RS485 
> link with external devices.
> 
> I've written some sample code to test out comms (see below). My initial 
> testing confused me as I was recieving corrupted messages. Further 
> investigation with serial port sniffer programs seemed to indicate that I 
> was sending corrupt data. I have used a demo version of "Serial Port 
> Monitor" from http://www.eltima.com/products/serial-port-monitor to monitor 
> the transmission below is what was output. To simplify my testing I have 
> put a loopback connector on COM1, so I should be seeing what I transmit. 
> This allowed me to see that I was transmitting far more characters than I 
> was expecting. It seems like I'm getting some sort of buffer overrun. I've 
> even simplified the code from that shown below, removing the code in the 
> Serial1.DataAvaliable event, this makes no change.
> 
> Could someone with more Knowledge that me please point out where I am going 
> wrong.
> 
> Regards
> 
> Martin Honeywill
> 
> 
> OUTPUT FROM SNIFFER PROGRAM
> ---------------------------
> 
> Open port COM1
> 
> 17:46:32 - Written data
> E0                                                    à               
> 
> 17:46:32 - Written data
> E0 8E                                                 àZ              
> 
> 17:46:32 - Written data
> E0 8E 37 E0 8E 37 00 E0 8E 37 00 C5 37 00 C5          àZ7àZ7.àZ7.Å7.Å 
> 
> 17:46:32 - Read data
> E0 E0 8E E0 8E 37 E0 8E 37 00 E0 8E 37 00 C5 37       ààZàZ7àZ7.àZ7.Å7
> 00 C5 8E                                              .ÅZ   
> 
> 
> All I was expecting to send were the bytes E0 8E 37 00 C5, I have listed 
> below the complete source of my simple application, It looks like I am 
> sending E0 E0 8E E0 8E 37 E0 8E 37 00 E0 8E 37 00 C5 37 00 C5 8E 
> 
> 
> SOURCE CODE
> -----------
> 
> Window1.Open:
> Sub Open()
>   if  not Serial1.open then msgBox"Port Failed"
>   Serial1.Baud=10 'Baud19200
>   Serial1.bits=3
>   Serial1.Parity=0 ' ParityNone
>   Serial1.Stop=2 'StopBits2
>   Serial1.Reset
> End Sub
> 
> Window1.Serial1.DataAvailable:
> Sub DataAvailable()
>   dim fred as String
>   dim i As integer
>   dim ch As integer
>   dim hexch As String
>   
>   fred=Me.ReadAll
>   
>   for i=1 to len(fred)
>     ch=ascB(midB(fred,i,1))
>     hexch=hex(ch)+" "
>     if lenb(hexch) =2 then hexch="0"+hexch
>     if bitwise.BitAnd(ch, &hF0) = &hC0 then hexch=hexch+chr(13)
>     RxData=RxData+hexch
>   next
>   
>   RxDataDisp.text=RxData
> End Sub
> 
> Window1.PushButton1.Action:
> Sub Action()
>   ' E0 8E 37 00 C5
>   serial1.write chrb(&he0)
>   serial1.write chrb(&h8e)
>   serial1.write chrb(&h37)
>   serial1.write chrb(&h00)
>   serial1.write chrb(&hc5)
>   'Serial1.XmitWait
> End Sub
> 
> Window1.PushButton2.Action:
> Sub Action()
>   RxData = ""
>   RxDataDisp.text=RxData
> End Sub
> 
>           

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>