Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hex output in Qbasic!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Can you tell me if I must do something special to send HEX data from qbasic to a comport? Is it ok when i write:
PRINT #1, and here the hex data? after i have opened port of course! Would be helpfull!
Thanks in advance and best regards

Phil
 
Hi,
Try
print #1, &HFF;


The &H says the number is a HEX number.
&O works if you want to send OCTAL.

Pappy
 
I made like this:
Print #1, (H&FF) + (H&FF) + and so on but no output... must i write checksum? and how it`s possible to send AT strings like ATZ 1234 ?

b. r.

Phil
 
Thanks, I`ll try and and report if worked or not...

best regards

Phil
 
So if I wanna send the string "AT" with hex data. What to do? I need example... A is 41 and T is 54 in hex so how to bring togehter??? Help me please!

Philipp
 
Hi,

Look and run the following. It should give you some ideas.

a$ = "AT"
h = &H0
FOR x = 0 TO 255

b$ = CHR$(h)
h = h + 1

c$ = a$ + b$
PRINT c$; " ";
NEXT x

Good Luck,

Pappy
 
Writing data to a COM port requires that the data be binary in form. The PRINT command by default converts numbers to base 10 for display, and not base 256. The CHR$() function converts a number between 0 and 255 into the corresponding digit in base 256, which can then be transferred to the COM port. As for representing the number itself, what Pappy1942 said is essentially correct; a number preceded by &H is treated as hexadecimal -- base 16 -- while a number preceded by &O is treated as octal, base 8. If you wanted to send a carriage return & linefeed pair (characters D and A in hexadecimal, respectively) to the COM port open as file #1, you would do the following:

[tt]PRINT #1, CHR$(&HD); CHR$(&HA);[/tt]

Note the semicolon at the end, which prevents QB from inserting its own newline information. QuickBASIC seldom understands the needs of serial connection protocols, so it is best to handle them yourself. Hope this helps =}
 
Hi,

A byte(8 bits) of info can be represented in many forms.
For instance

Binary 0100 0001
Octal 101
Hex 41
Decimal 65
ASCII A

are all the same thing just different ways of saying it . Octal and Hex are used to make reading easier.

01000001
10010011
10001111
is a lot harder to read than
41
93 HEX NUMBERS for above binary
8F


If you send an A (PRINT #1, "A";) to the comm port(#1) and watch the output with an OScope the binary bits as pictured above (01000001) plus the start and stop bits.

There is no way to send an ascii "A" or a Hex65 down the line without it being 1's and 0's.

Hope this starts to clear it up.

Pappy




 
Working!!! Thanks a lot! You all saved my live! Thanks! Great forum, great people.

B. R.

Philipp
 
Now next (-->and I hope last problem..)
I must have timer which stops for 0.1 second on EVERY computer. Not:
for i = .... next i ....
Because depends of speed of PC

Philipp
 
Hi, Philipp. You could user the TIMER function but that isn't very precise. Take a look at thread314-20062. I posted some code on October 22 that takes a fairly low-level approch to this subject.

Of course, if you aren't concerned with pausing for exactly 0.1 seconds, you could always use the TIMER.

This snippet will pause your app for "about" one tenth of a second on all computers. Sorry about the "about" part. The system timer isn't known for great accuracy.
[tt]
OldTime# = TIMER
DO
IF TIMER >= OldTime# + .1 THEN EXIT DO
LOOP
[/tt]

If this doesn't solve your problem you may want to create a new thread, specifically addressing the issue.
VCA.gif

Alt255@Vorpalcom.Intranets.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top