Can AutoLisp read byte?

Can AutoLisp read byte?

Anonymous
Not applicable
1,803 Views
9 Replies
Message 1 of 10

Can AutoLisp read byte?

Anonymous
Not applicable

Hello

 

I have a hardware that can return date value. By using C#, I am able to read all 16 data in bytes.

However, when I try to use it with AutoLisp, it only able to read 3 data.

 

Example:

 

(print Buffer)

 

"á\007\004"   

 

it is missing 13 more data.

 

Is there any restriction on number of data that AutoLisp can read?

 

 

Thank you

 

0 Likes
1,804 Views
9 Replies
Replies (9)
Message 2 of 10

Alexander.Rivilis
Mentor
Mentor

Zero-symbol ("\000") mark the end of string. So you can not print string like this: "string1\000string2":

 

Command: (print "string1\000string2") "string1"

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 3 of 10

wkmvrij
Advocate
Advocate

This might help you :

 

(DEFUN rb (/ buffer char fh)
  (SETQ	fh (OPEN "C:\\Data\\Acad\\LSP\\web\\ArcAndChordLengths.dwg"
		 "r"
	   )
	n  -1
  )
  (WHILE (< (SETQ n (1+ n)) 16)
    (SETQ char (READ-CHAR fh))
    (SETQ buffer (CONS char buffer))
  )
  (IF fh
    (SETQ fh (CLOSE fh))
  )
  (REVERSE buffer)
)

These are the first 16 bytes of a DWG file containing a number of HEX 00 values. Although read-char returns only decimal values you should be able to cast it back to hex values one way or another to use the value of your hardware reading. Here read-char uses a file to read from You may perhaps store the value of your hardware in a temporary file for LSP to open?

0 Likes
Message 4 of 10

john.uhden
Mentor
Mentor

I tried reading .DWG files via Autolisp years ago, character by character, and I think I recall that it ceases on the first instance of ^Z which is an old DOS end of file marker, even though it was nowhere near the end of the file.

John F. Uhden

0 Likes
Message 5 of 10

wkmvrij
Advocate
Advocate

One would still need to be on the lookout for the end of file marker reading binary files. I do not recall at his moment what the rules are for the use of it, but in the case of this thread one is looking for the value of a memory buffer filled by a hardware device. This must have a given length, so using a numbered loop would do it. If the length of the resulting list  is not equal to the length of the buffer one would use the resulting error.

 

How to make the memory buffer available to be read by lisp is another puzzle. I have no answer for that other than store the buffer in a file and give the file to read by lsp You may have suggestions?

0 Likes
Message 6 of 10

Alexander.Rivilis
Mentor
Mentor

Maybe this code help you: http://www.theswamp.org/index.php?topic=17465.0

 

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

0 Likes
Message 7 of 10

wkmvrij
Advocate
Advocate

Please clarify how you came to give your lsp variable 'buffer' its value? 

0 Likes
Message 8 of 10

Anonymous
Not applicable

Yes! This is the reason! I just check the data came in using C# and found that there is 0 value which could be read as \000.

In this case i'll need to make the program skip \000 when reading. 

 

Thank you this gave me something to look at. 

0 Likes
Message 9 of 10

Anonymous
Not applicable

I use (vlax-get-property app "Buffer")

0 Likes
Message 10 of 10

wkmvrij
Advocate
Advocate

I have a gut feeling that the lisp 'buffer variable contains a safearray. Pls confirm by using VLIDE and stepping through your code until you have setq'ed your 'buffer variable and inspect it . If true you need to have a completely different approach to reading the various values in the array of bytes delivered to LSP.

 

With these external hardware devices I would expect that a byte containing 0x00 is meaningfull one way or another and not to be omitted out of hand