[Gambas-user] Serial port data being changed ????

Doriano Blengino doriano.blengino at ...1909...
Tue Dec 8 20:05:08 CET 2009


Ron ha scritto:
> Benoît Minisini schreef:
>   
>>> mike wrote:
>>>     
>>>       
>>>> I'm having trouble with Gambas and the serial ports.
>>>> Something is changing binary &h0d to &h0a when received
>>>> from a serial port. I noticed it in a program that I've
>>>> been working on that receives packets of binary data
>>>> from a microprocessor. I wrote a little test program to
>>>> demonstrate the problem and have included it below. I also
>>>> reprogrammed the micro to simply send &h0d as long a
>>>> pushbutton is held depressed. I have verified that the
>>>> correct data is indeed being sent using CuteCom to display
>>>> the binary data.
>>>> An interesting thing that I noticed when I ran CuteCom to
>>>> test the data being received is that if I close CuteCom without
>>>> closing the serial port first then run my Gambas program, it works
>>>> fine until I restart the system. If I close the port before closing
>>>> CuteCom then my Gambas program fails.
>>>>
>>>>
>>>> This is the code for the test program.
>>>>
>>>> ' Gambas class file
>>>> ' Using Gambas 2.18 on a system running
>>>> ' Fedora Kernel (26.30.9-102.fc11.x86_64)
>>>> ' It also fails running Gambas 2.11
>>>> ' on my laptop running
>>>> ' Fedora Kernel (2.6.27.25-78.2.56.fc9.i686)
>>>>
>>>> PUBLIC SUB Form_Open()
>>>>
>>>>    ME.Center
>>>>
>>>> ' Setup the serial port - 9600,8,N,1
>>>>
>>>> '  SerPort1.PortName = "/dev/ttyS0"     ' Both ports fail
>>>>    SerPort1.PortName = "/dev/ttyUSB0"    ' This the port I'll eventually
>>>> use SerPort1.Speed = "9600"               ' because the laptop has no
>>>> serial port.
>>>>    SerPort1.DataBits = "8"
>>>>    SerPort1.Parity = "0"
>>>>    SerPort1.StopBits = "1"
>>>>    SerPort1.Open
>>>>
>>>>    TextArea1.Text = SerPort1.PortName & Chr$(10)
>>>> END
>>>>
>>>> PUBLIC SUB SerPort1_Read()
>>>>
>>>> ' A microprocessor is connected to the serial port and
>>>> ' continuously sends &h0d (CR) as long a push button is held down.
>>>>
>>>> DIM InByte AS Byte
>>>>
>>>>    READ #SerPort1, InByte
>>>>    TextArea1.Insert(Hex$(InByte) & " ")
>>>> ' The textarea displays a series of "A " (LF) instead of "D " (CR)
>>>> END
>>>>
>>>> PUBLIC SUB ExitBtn_Click()
>>>>
>>>>    SerPort1.Close
>>>>    QUIT
>>>> END
>>>>
>>>> PUBLIC SUB ClearBtn_Click()
>>>>
>>>>    TextArea1.Clear
>>>> END
>>>>       
>>>>         
>>> This is a Linux thing. Not Gambas. The icrnl flaf is set as standard.
>>> Easiest way is to use stty to change it.
>>>
>>> SHELL "stty -F " & SerPort1.PortName & " -icrnl"
>>>
>>>     
>>>       
>> I'm not a serial port user at all, and I find that behaviour a bit strange.
>>
>>   
>>     
>
> Me too.
>
> I have build serial support for about 10 different hardware devices in 
> my Gambas project both binary and ASCII and didn't stumble upon this 
> strange behavior (yet?)
>   
Could it be that some other process is using the port (getty, mgetty)? 
And that that process programs the serial driver? Because those stty 
things should be related, I think, to terminal devices, not general 
serial drivers as used by pppd, for example.

Just put this way - I really don't know.
Regards,

-- 
Doriano Blengino

"Listen twice before you speak.
This is why we have two ears, but only one mouth."





More information about the User mailing list