Re: [Gambas-user] Serial I/O with byte data

2017-05-16 Thread Mike Crean
Hi, as I said before most likely Modbus RTU or similar protocol. If so you will 
need to do some BIT bashing and probably 
some CRC conversion. You will need to know the frame size among other things.

Public Sub HbLb()
  Dim Xz2 As Long
  Hb = Fix(DataS / 256)
  Xz2 = Fix(256 * Hb)
  Lb = DataS - Xz2
End
RegardsMike
 

On Monday, 15 May 2017, 23:29, ML  wrote:
 

 Alex,

Without knowing the protocol/device you're communicating with, I don't
think anyone will be able to give substantial help.
But, after years of interfacing very diverse hardware via RS-232 (fiscal
printers, cash-hanlding hardware, GPS, you name it!), I can tell you
that it's not always easy, and docs sometimes lack info or are plain wrong.
Unfortunately the bulk of my experience with hardware is in VB6...
Maybe you're looking at some kind of protocol wrapper bytes... Can't
really say without the detail.

On 15/05/17 08:52, alexchernoff wrote:
> Thanks, it works (both with .tostring and reading one by one...
> But I get values I don't know how to convert, e.g. where I expect a
> decimal 83 or hex 53 I get byte value of 253 ... Or instead of Decimal
> 15 I get 225 :(
> cheers!


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


   
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-16 Thread alexchernoff
it works fine - it was a strange serial port hardware issue. All the "Read"
methods suggested above work, Thanks to all!




--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58995.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread ML
Alex,

Without knowing the protocol/device you're communicating with, I don't
think anyone will be able to give substantial help.
But, after years of interfacing very diverse hardware via RS-232 (fiscal
printers, cash-hanlding hardware, GPS, you name it!), I can tell you
that it's not always easy, and docs sometimes lack info or are plain wrong.
Unfortunately the bulk of my experience with hardware is in VB6...
Maybe you're looking at some kind of protocol wrapper bytes... Can't
really say without the detail.

On 15/05/17 08:52, alexchernoff wrote:
> Thanks, it works (both with .tostring and reading one by one...
> But I get values I don't know how to convert, e.g. where I expect a
> decimal 83 or hex 53 I get byte value of 253 ... Or instead of Decimal
> 15 I get 225 :(
> cheers!


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread d4t4full
 is ASCII for STX, a special char that for some protocols mean "start 
transmission".
Some protocols frame their data payload between chars STX () and ETX().
These also normally use some checksum mechanism either before or right after 
ETX.

Of course it could also be a misleading UTF8 header of some kind resulting from 
raw data to string conversion, but that I cannot tell for sure.

You need a good protocol manual and check low-level comms frames.

Regards,
zxMarce.

On May 15, 2017, 10:42, at 10:42, alexchernoff  wrote:
>Hmm eureka, it's 02 53 = 0x53
>Or 02 25 = 0x25...
>
>Where could that 02 be from?
>
>Cheers!
>
>
>
>--
>View this message in context:
>http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58986.html
>Sent from the gambas-user mailing list archive at Nabble.com.
>
>--
>Check out the vibrant tech community on one of the world's most
>engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>___
>Gambas-user mailing list
>Gambas-user@lists.sourceforge.net
>https://lists.sourceforge.net/lists/listinfo/gambas-user
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread alexchernoff
Hmm eureka, it's 02 53 = 0x53
Or 02 25 = 0x25...

Where could that 02 be from?

Cheers!



--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58986.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread alexchernoff
Thanks, it works (both with .tostring and reading one by one... 

But I get values I don't know how to convert, e.g. where I expect a decimal
83 or hex 53 I get byte value of 253 ... Or instead of Decimal 15 I get 225
:(

cheers!



--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58984.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread nando_f
My reply to the comment:

> Gambas Strings are not null-terminated and can
> contain any sequence of bytes, which includes non-printable characters
> (which I think is what you meant by "unreadable" characters).

You should always consider String as an array of bytes.
Just because humans can't read them or because they cannot be displayed,
means nothing to the computer.  It only means something to the human.

While the computer is processing and doing work, we don't need to see it.

I use string exclusively for binary data...especially serial port stuff.
Strings are far easier than a byte array.

If you insist on using a byte array, consider a large fixed-size array.
For example: b[1].
Resizing a dynamic array every time is cpu work.

-Fernando


--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: Mike Crean <mike.cr...@y7mail.com>
To: mailing list for gambas users <gambas-user@lists.sourceforge.net>
Sent: Mon, 15 May 2017 10:46:01 +0000 (UTC)
Subject: Re: [Gambas-user] Serial I/O with byte data

> If you are talking about a byte the likes of that used in modbusrtu you will 
> need to do some high low bit manipulation on it. RegardsMike
> 
> On Monday, 15 May 2017, 13:19, Alexie <uale...@gmail.com> wrote:
> 
>  Following should work for you:
> 
> Public Sub XXX_Read()
> 
>   Dim iLen As Integer
>   Dim aData As Byte[]
> 
>   iLen = Lof(Last)
>   aData = New Byte[]
>   aData.Resize(iLen)
>   Try aData.Read(Last, 0, iLen)
> 
> End
> 
> You need to get the length (lof) first, then resize array ... only then you
> can read it.
> 
> 2017-05-14 21:56 GMT+02:00 Tobias Boege <tabo...@gmail.com>:
> 
> > On Sun, 14 May 2017, alexchernoff wrote:
> > > Good day all,
> > >
> > > Anyone know how to read data received on serial port into an array of
> > bytes
> > > instead of string?
> > >
> >
> > I think that's not possible.
> >
> > > String gets unreadable binary characters, so how can I
> > > put them into byte[] or so?
> > >
> >
> > This shouldn't be a problem. Gambas Strings are not null-terminated and can
> > contain any sequence of bytes, which includes non-printable characters
> > (which
> > I think is what you meant by "unreadable" characters).
> >
> > If you insist on a Byte[], read it into a String and use
> > Byte[].FromString(),
> > but there is no way to go around the String, AFAICT (and that is because
> > there is no need to, as Strings can handle binary data just fine).
> >
> > Regards,
> > Tobi
> >
> > --
> > "There's an old saying: Don't change anything... ever!" -- Mr. Monk
> >
> > 
> > --
> > Check out the vibrant tech community on one of the world's most
> > engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> > ___
> > Gambas-user mailing list
> > Gambas-user@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-15 Thread Mike Crean
If you are talking about a byte the likes of that used in modbusrtu you will 
need to do some high low bit manipulation on it.
RegardsMike
 

On Monday, 15 May 2017, 13:19, Alexie  wrote:
 

 Following should work for you:

Public Sub XXX_Read()

  Dim iLen As Integer
  Dim aData As Byte[]

  iLen = Lof(Last)
  aData = New Byte[]
  aData.Resize(iLen)
  Try aData.Read(Last, 0, iLen)

End

You need to get the length (lof) first, then resize array ... only then you
can read it.

2017-05-14 21:56 GMT+02:00 Tobias Boege :

> On Sun, 14 May 2017, alexchernoff wrote:
> > Good day all,
> >
> > Anyone know how to read data received on serial port into an array of
> bytes
> > instead of string?
> >
>
> I think that's not possible.
>
> > String gets unreadable binary characters, so how can I
> > put them into byte[] or so?
> >
>
> This shouldn't be a problem. Gambas Strings are not null-terminated and can
> contain any sequence of bytes, which includes non-printable characters
> (which
> I think is what you meant by "unreadable" characters).
>
> If you insist on a Byte[], read it into a String and use
> Byte[].FromString(),
> but there is no way to go around the String, AFAICT (and that is because
> there is no need to, as Strings can handle binary data just fine).
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


   
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-14 Thread Alexie
Following should work for you:

Public Sub XXX_Read()

  Dim iLen As Integer
  Dim aData As Byte[]

  iLen = Lof(Last)
  aData = New Byte[]
  aData.Resize(iLen)
  Try aData.Read(Last, 0, iLen)

End

You need to get the length (lof) first, then resize array ... only then you
can read it.

2017-05-14 21:56 GMT+02:00 Tobias Boege :

> On Sun, 14 May 2017, alexchernoff wrote:
> > Good day all,
> >
> > Anyone know how to read data received on serial port into an array of
> bytes
> > instead of string?
> >
>
> I think that's not possible.
>
> > String gets unreadable binary characters, so how can I
> > put them into byte[] or so?
> >
>
> This shouldn't be a problem. Gambas Strings are not null-terminated and can
> contain any sequence of bytes, which includes non-printable characters
> (which
> I think is what you meant by "unreadable" characters).
>
> If you insist on a Byte[], read it into a String and use
> Byte[].FromString(),
> but there is no way to go around the String, AFAICT (and that is because
> there is no need to, as Strings can handle binary data just fine).
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-14 Thread Tobias Boege
On Sun, 14 May 2017, alexchernoff wrote:
> Good day all, 
> 
> Anyone know how to read data received on serial port into an array of bytes
> instead of string?
>

I think that's not possible.

> String gets unreadable binary characters, so how can I 
> put them into byte[] or so? 
> 

This shouldn't be a problem. Gambas Strings are not null-terminated and can
contain any sequence of bytes, which includes non-printable characters (which
I think is what you meant by "unreadable" characters).

If you insist on a Byte[], read it into a String and use Byte[].FromString(),
but there is no way to go around the String, AFAICT (and that is because
there is no need to, as Strings can handle binary data just fine).

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-14 Thread alexchernoff
Good day all, 

Anyone know how to read data received on serial port into an array of bytes
instead of string?  String gets unreadable binary characters, so how can I 
put them into byte[] or so? 

Thanks! 



--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58977.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-10 Thread T Lee Davidson
On 05/08/2017 12:13 PM, alexchernoff wrote:
> Dear all,
> 
> I am receiving data over a serial port which is sent by a byte[].write
> function (an array of bytes)
> 
> I get the SerialPort1_read() event raised where I try to read data, RxBuffer
> is a string var
> 
> *Try Read #SerialPort1, RxBuffer, Lof(SerialPort1)*
> 
> as soon as I do, the whole program stops, some other timers in other modules
> also stop to fire. In fact when running the program in Gambas again, it does
> not execute even the startup, so have to restart the IDE.
> 
> what am I doing wrong?
> 
> thanks!

If you are attempting to read the data _into_ RxBuffer, it appears your syntax 
is incorrect.

According to http://gambaswiki.org/wiki/lang/read , the syntax for the READ 
statement is:
Variable = READ [ # Stream , ] Length

Perhaps try:
Try RxBuffer = Read #SerialPort1, Lof(SerialPort1)


---
Lee


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-09 Thread nando_f
I have used Gambas serial port for 12 years now without problems.

If there is nothing in the serial port queue, then that line might block.

I use this:

. . .
L=Lof(Sport) 'how much is there now?
if L>1 then L=L-1'leave at least one byte for next time around.
if L>0 then Read #Sport, Rx, L   'get all less one byte
Rx_all = Rx_all + Rx 'combine this piece into the whole receive 
string.
Rx=""'just in case it loops around, don't re-read 
Rx.
. . .


Most importantly, please do not think that just one READ will
retrieve a whole line or chunk of data from your serial port.
It will get only part of it because your computer reads bytes much faster
and empties the receiver buffer much faster than data send over RS232.

-Fernando

--
Open WebMail Project (http://openwebmail.org)


-- Original Message ---
From: alexchernoff <alexchern...@hotmail.com>
To: gambas-user@lists.sourceforge.net
Sent: Mon, 8 May 2017 22:45:11 -0700 (MST)
Subject: Re: [Gambas-user] Serial I/O with byte data

> Thanks Mike,
> 
> what I have is pretty much the same, it's this line that causes everything
> to stop.
> 
> *Read #Sport, Rx, Lof(Sport) *
> 
> A very similar program written in Xojo on the same system using same serial
> port works just fine. In Gambas, things just stop executing as soon as I do
> a Read on that port...
> 
> --
> View this message in context: 
> http://gambas.8142.n7.nabble.com/Serial-I-O-with-
> byte-data-tp58933p58939.html Sent from the gambas-user mailing list archive 
> at Nabble.com.
> 
> --
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> ___
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
--- End of Original Message ---


--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-08 Thread alexchernoff
Thanks Mike,

what I have is pretty much the same, it's this line that causes everything
to stop. 

*Read #Sport, Rx, Lof(Sport) *

A very similar program written in Xojo on the same system using same serial
port works just fine. In Gambas, things just stop executing as soon as I do
a Read on that port...



--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933p58939.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


Re: [Gambas-user] Serial I/O with byte data

2017-05-08 Thread Mike Crean
Hi Alex, have a look at this code for some ideas how I have serial comms 
working.
' Gambas class file

Private Sport As SerialPort
Public Pp As Byte
Public Po As Byte
Public Rxs As String

Public Sub Form_Open()
  Me.Load
  Me.Center
End

Public Sub Button2_Click()
  Sport = New SerialPort As "Sport"
  Po = 1
  
  If TextBox3.Text = "N" Or TextBox3.Text = "n" Then
    pp = 0
  End If
  
  With Sport
    .PortName = TextBox1.Text
    .Speed = TextBox2.Text
    .Parity = Pp
    .DataBits = TextBox4.Text
    .StopBits = TextBox5.Text
    .FlowControl = Val(TextBox6.text)
  Try
    .Open()
    Label9.Text = TextBox1.Text & ":" & TextBox2.Text & "," & TextBox3.Text & 
"," & TextBox4.Text & "," & TextBox5.Text & "  OPEN"
    Label10.Background = &  
    If Error Then
  Message(" Port " & TextBox1.Text & " not found -- TERMINATING PROGRAM")
  Quit
    Endif
  End With

End

Public Sub Sport_Read()
  Dim Rx As String
  Read #Sport, Rx, Lof(Sport)
  Rxs = Rxs & Rx
  If Rx = Chr$(13) Then
    TextArea1.Text = TextArea1.Text & Rxs
    Rxs = ""
  End If
End

Public Sub Button1_Click()
  If Po = 0 Then
    Message("Open the PORT")
  Else
    Print #Sport, Textbox7.Text; Chr$(13)
  End If
End

Public Sub Button3_Click()
  Sport.Close
  Label10.Background = &
  Label9.Text = "CLOSED"
  Po = 0
End

Public Sub Button4_Click()
  TextArea1.Clear
End

Public Sub Button5_Click()
  EndIt()  
End

Public Sub Form_Close()
  EndIt()
End

Public Sub EndIt()
  Try
    Sport.Close
    Quit
  If Error Then
    Quit  
  Endif
End


RegardsMike
 

On Tuesday, 9 May 2017, 0:12, alexchernoff  wrote:
 

 Dear all,

I am receiving data over a serial port which is sent by a byte[].write
function (an array of bytes)

I get the SerialPort1_read() event raised where I try to read data, RxBuffer
is a string var

*Try Read #SerialPort1, RxBuffer, Lof(SerialPort1)*

as soon as I do, the whole program stops, some other timers in other modules
also stop to fire. In fact when running the program in Gambas again, it does
not execute even the startup, so have to restart the IDE. 

what am I doing wrong?

thanks!




--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


   --
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user


[Gambas-user] Serial I/O with byte data

2017-05-08 Thread alexchernoff
Dear all,

I am receiving data over a serial port which is sent by a byte[].write
function (an array of bytes)

I get the SerialPort1_read() event raised where I try to read data, RxBuffer
is a string var

*Try Read #SerialPort1, RxBuffer, Lof(SerialPort1)*

as soon as I do, the whole program stops, some other timers in other modules
also stop to fire. In fact when running the program in Gambas again, it does
not execute even the startup, so have to restart the IDE. 

what am I doing wrong?

thanks!




--
View this message in context: 
http://gambas.8142.n7.nabble.com/Serial-I-O-with-byte-data-tp58933.html
Sent from the gambas-user mailing list archive at Nabble.com.

--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
___
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user