Getting Data from Serial

Post your Gambas programming questions here.
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Getting Data from Serial

Post by thatbruce »

(Quicky)
I think the minimal thing we can deal with is a Byte. You can Or or And bytes with some mask (usually a Const or an Enum) to see if one or more bits are set.
e.g.

Code: Select all

Const elephant as Byte=3
...
Function IsItAnElephant(this as Byte) as Boolean
	If And(this, elephant) then Return True
	Return False
End
Mneh. It looks right to me but I haven't actually tried it.

hth
thatbruce
Have you ever noticed that software is never advertised using the adjective "spreadable".
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Getting Data from Serial

Post by grayghost4 »

here are all the gambas bit functions :D

https://gambas-buch.de/dwen/doku.php?id=k9:k9.9:start

since you are working with serial port ... this might be of intrest

https://gambas-buch.de/dwen/doku.php?id ... .1.5:start
vuott
Posts: 262
Joined: Wednesday 5th April 2017 6:07pm
Location: European Union

Re: Getting Data from Serial

Post by vuott »

AndyGable wrote: Saturday 12th November 2022 5:51pm ... I get a Error message on Bit saying "Unknown Identifier"
Of course, the Bit () function in Gambas does not exist, nor is it a function or class that you have created.

AndyGable wrote: Saturday 12th November 2022 5:51pm So does anyone now the Gambas option for Bit?
What should Bit () do? :|
Europaeus sum !

Amare memorentes atque deflentes ad mortem silenter labimur.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

grayghost4 wrote: Sunday 13th November 2022 6:55pm here are all the gambas bit functions :D

https://gambas-buch.de/dwen/doku.php?id=k9:k9.9:start

since you are working with serial port ... this might be of intrest

https://gambas-buch.de/dwen/doku.php?id ... .1.5:start
that last one does seem to help

I just can not get a reliable data from the prnter either i get 20015 (all good) or it comes like 200152001520015 so is my app not clearing the data some where?
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Getting Data from Serial

Post by grayghost4 »

AndyGable wrote: ↑Saturday 12th November 2022 12:51pm
So does anyone now the Gambas option for Bit?

What should Bit () do? :|
see my post above


Print BTst(0, 0) ........ prints false least significant bit is 0
Print BTst(1, 0) ........ returns True least significant bit is 1
Print BTst(2, 1) ..........returns True bit two is a 1

Function Description
BClr (Number, Bit) Returns number with deleted bit' Bit'.
BSet (Number, Bit) Returns number with bit' Bit' set.
BTst (Number, Bit) Returns True if bit' Bit' is set, otherwise False.
BChg (Number, Bit) Returns Number whose bit' Bit' was inverted.
Lsl (Number, Bit) Each bit in the bit sequence of Number is shifted to the left by' Bit' bits. For the left-hand bits that are omitted, zero bits are attached to the right-hand side. The sign is ignored. (Lsl = logical shift left)
Lsr (Number, Bit) Each bit in the bit sequence of Number is shifted to the right by' Bit' bits. Zero bits are inserted on the left for the bits that are omitted on the right. (Lsr = logical shift right)
Shl (Number, Bit) Each bit in the bit sequence of Number is shifted to the left by' Bit' bits. For the left-hand bits that are omitted, zero bits are attached to the right-hand side.
Asl (Count, Bit) Synonym for Shl (count, bit). The sign is not ignored.
Shr (Number, Bit) Each bit in the bit sequence of Number is shifted to the right by' Bit' bits. The sign bit is inserted on the left for the bits that are omitted on the right.
Asr (Number, Bit) Synonym for Shr (Number, Bit)
Rol (Number, Bit) During the operation Rol, the bits rotate by the number of' bits' as if MSB (most significant bit - highest value bit position) and LSB (less significant bit - lowest value bit position) were connected to each other. The bit that is shifted out of the bit sequence to the left has the same value as the bit that is shifted in from the right. (Rol = Rotate left)
Ror (Number, Bit) During operation Ror(), the bits rotate by the number of 'bits' as if MSB and LSB were connected to each other. The bit that is shifted out of the bit sequence to the right has the same value as the bit that is shifted in from the left.
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

Re: Getting Data from Serial

Post by AndyGable »

Man things gets complicate quickly.

Anyone willing to write me the module give me a quote for doing this :)
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: Getting Data from Serial

Post by grayghost4 »

This thread has gotten so convoluted That I don't think anyone can follow it .( at least I can't )

If you were to start a NEW thread and post a page or two of the manual for the printer, (or a link to it ) and your code that you have.

Someone may be inclined to look at it and try to help :)
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: Getting Data from Serial

Post by thatbruce »

I don't think it's that hard.
The algorithm would seem to be
1) sent the status request to the printer. That should, AFAICT according to ANdy's manual quotes, to get the drawer state
2) wait for the response, which as Andy has seen is a single byte!
3) get the byte
4) mask it with a set of constants that "check" the bits of interest and set status variables as you want them

Crikey we used to do this all the time back in the good old days when all we had to implement serial printer interfaces was FORTRAN IV.
It's not that hard and in the end eminently readable when you come back to it weeks/months later. Stop thinking about the bits, they are not important.Don't bother about converting it to this that or the other, just understand how "bit maps" work... And and Or

In this case the bitmask for the "Drawer state" commend is to my way of thinking P###F##F where P is the drawer state, # is I don't care and F is some secret known only to the printer.
so

Code: Select all

Const $DrawerIn As Byte =  Bin(10000000) ' Just to make it easy for the binary freaks
Const $DrawerOut As Byte = Bin(01111111) ' Not even really necessary if you read below

...
' in the test method

If And(MyByte, $DrawerIn) then
	 $drawerstate = "IN"
else
	$drawerstate = "OUT"  '  See, if it aint in then it must be out (said the actress to the bishop)
EndIf

etc
best of luck
thatbruce
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply