Hi Everyone
I was hoping someone could advice me how I can send text to the Serial port with Gambas 3.
I have according to my code the port open but I can not work out how to send data to the device (it is a small LCD screen)
I want to first get it to show "Hello World"
any advice would be most welcomed
[Solved] Sending Data to the Serial Port
-
- Posts: 362
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
[Solved] Sending Data to the Serial Port
Last edited by AndyGable on Wednesday 17th February 2021 5:08pm, edited 1 time in total.
Re: Sending Data to the Serial Port
Sounds like an interesting challenge Andy.
If you haven't already done so, I'd suggest doing a test first to establish that all is OK with your hardware.
Are you connecting an RS232 port from a computer to your mini-LCD display?
You will need protocol information for your display (e.g. how to set baud rates, flow control & so on).
If you haven't already done so, I'd suggest doing a test first to establish that all is OK with your hardware.
Are you connecting an RS232 port from a computer to your mini-LCD display?
You will need protocol information for your display (e.g. how to set baud rates, flow control & so on).
Re: Sending Data to the Serial Port
...once you have proved that your computer can communicate with your display using a program like minicom, you could try a bit of Gambas like this:-
Public Sub Form_Open()
With SerialPort1
.PortName = "/dev/ttyS0" 'needs to be appropriate for your computer
.Speed = 1200 'must match printer
.FlowControl = SerialPort.Hardware 'must match printer
.DataBits = SerialPort.Bits7 'must match printer
.StopBits = SerialPort.Bits1 'must match printer
.Parity = SerialPort.Even 'must match printer
.Send = "Hello World!"
End With
End
...I wish I could rig up a serial comms test-bed and play along with you!Re: Sending Data to the Serial Port
You also have to make sure that you add yourself to the "dialout" group in your Linux system. (for example open a terminal and type: sudo adduser your_name dialout).
As mentioned above, first try it with a standard serial communication software to see if the hardware works. Personally, I prefer either Moserial or Cutecom for simple communication.
As mentioned above, first try it with a standard serial communication software to see if the hardware works. Personally, I prefer either Moserial or Cutecom for simple communication.
-
- Posts: 362
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Sending Data to the Serial Port
I have tried your example and I get the following error on .sendstevedee wrote: ↑Sunday 14th February 2021 1:48pm ...once you have proved that your computer can communicate with your display using a program like minicom, you could try a bit of Gambas like this:-
...I wish I could rig up a serial comms test-bed and play along with you!
Public Sub Form_Open() With SerialPort1 .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer .Speed = 1200 'must match printer .FlowControl = SerialPort.Hardware 'must match printer .DataBits = SerialPort.Bits7 'must match printer .StopBits = SerialPort.Bits1 'must match printer .Parity = SerialPort.Even 'must match printer .Send = "Hello World!" End With End
Code: Select all
'SerialPort.Send is not a property in FMain:14
Re: Sending Data to the Serial Port
Sorry Andy, I'm an idiot. Send is a method.
Also you may need to use the Begin method, so try:-
Also you may need to use the Begin method, so try:-
Public Sub Form_Open()
With SerialPort1
.PortName = "/dev/ttyS0" 'needs to be appropriate for your computer
.Speed = 1200 'must match printer
.FlowControl = SerialPort.Hardware 'must match printer
.DataBits = SerialPort.Bits7 'must match printer
.StopBits = SerialPort.Bits1 'must match printer
.Parity = SerialPort.Even 'must match printer
.Begin()
.Send("Hello World!")
End With
End
-
- Posts: 362
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Sending Data to the Serial Port
Hey Thanks for the advice Stevedee but now I am getting "Too many arguments in FMain:15 on the .Send("Hello World!") line any advice?stevedee wrote: ↑Monday 15th February 2021 3:56pm Sorry Andy, I'm an idiot. Send is a method.
Also you may need to use the Begin method, so try:-
Public Sub Form_Open() With SerialPort1 .PortName = "/dev/ttyS0" 'needs to be appropriate for your computer .Speed = 1200 'must match printer .FlowControl = SerialPort.Hardware 'must match printer .DataBits = SerialPort.Bits7 'must match printer .StopBits = SerialPort.Bits1 'must match printer .Parity = SerialPort.Even 'must match printer .Begin() .Send("Hello World!") End With End
Re: Sending Data to the Serial Port
Sorry, I'm not doing very well with this one, am I.
Looking more closely, the Send method does not take any arguments, so should be replaced by .Send()
I was hoping that there was an easy way to send some text, but the documentation says you need to establish a Stream and then use Stream methods to send & receive data.
I'll try to look at this again when I have more time.
Looking more closely, the Send method does not take any arguments, so should be replaced by .Send()
I was hoping that there was an easy way to send some text, but the documentation says you need to establish a Stream and then use Stream methods to send & receive data.
I'll try to look at this again when I have more time.
Re: Sending Data to the Serial Port
I am doing a lot of serial communications using Gambas.
Here is how I set it up:
Private Comm1 As SerialPort
' Com port initialization
Comm1.PortName = cbCom1.Text
Comm1.Speed = 115200
Comm1.Parity = Comm1.None
Comm1.DataBits = 8
Comm1.StopBits = 1
Comm1.FlowControl = Comm1.None
' Start by using a serial port buffer
Comm1.Begin
' Now write many bytes to that port in a for-loop or whatever way, using the command:
Write #Comm1, data As Byte
' Finally, the buffered data can be send using:
Comm1.Send
Here is how I set it up:
Private Comm1 As SerialPort
' Com port initialization
Comm1.PortName = cbCom1.Text
Comm1.Speed = 115200
Comm1.Parity = Comm1.None
Comm1.DataBits = 8
Comm1.StopBits = 1
Comm1.FlowControl = Comm1.None
' Start by using a serial port buffer
Comm1.Begin
' Now write many bytes to that port in a for-loop or whatever way, using the command:
Write #Comm1, data As Byte
' Finally, the buffered data can be send using:
Comm1.Send
-
- Posts: 362
- Joined: Wednesday 2nd December 2020 12:11am
- Location: Northampton, England
- Contact:
Re: Sending Data to the Serial Port
so how do I send the text "Hello World"?progger wrote: ↑Tuesday 16th February 2021 7:23pm I am doing a lot of serial communications using Gambas.
Here is how I set it up:
Private Comm1 As SerialPort
' Com port initialization
Comm1.PortName = cbCom1.Text
Comm1.Speed = 115200
Comm1.Parity = Comm1.None
Comm1.DataBits = 8
Comm1.StopBits = 1
Comm1.FlowControl = Comm1.None
' Start by using a serial port buffer
Comm1.Begin
' Now write many bytes to that port in a for-loop or whatever way, using the command:
Write #Comm1, data As Byte
' Finally, the buffered data can be send using:
Comm1.Send