Closed Rx-out closed 5 months ago
Please give an example of what you want to do
send hexadecimal data device
The string "01 03 00 80 00 07"
contains the character 0
, then the character 1
, then a space character, and so on.
Demonstration:
public static void main(String[] args) {
printStringBytesInHex("ABCD");
printStringBytesInHex("01 03 00 80 00 07");
}
private static void printStringBytesInHex(String str) {
final byte[] bytes = str.getBytes(java.nio.charset.StandardCharsets.US_ASCII);
for (int i = 0; i < bytes.length; i++) {
System.out.printf("%02X ", bytes[i]);
}
System.out.println();
}
Sample output:
41 42 43 44
30 31 20 30 33 20 30 30 20 38 30 20 30 30 20 30 37
Table of ASCII characters:
I will add JVisaInstrument methods to send bytes instead of a string.
It's not what I wanted, thank you! I don't speak English very well and didn't describe the problem clearly! Thank you very much for your reply ,It's a pleasure to communicate with you, can you leave a contact information?
------------------ 原始邮件 ------------------ 发件人: "Peter @.>; 发送时间: 2024年3月14日(星期四) 上午7:36 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [pfroud/JVisa] JVisa whether you can read and write 16-base data? (Issue #14)
The string "01 03 00 80 00 07" contains the character 0, then the character 1, then a space character, and so on.
Demonstration: public static void main(String[] args) { printStringBytesInHex("ABCD"); printStringBytesInHex("01 03 00 80 00 07"); } private static void printStringBytesInHex(String str) { final byte[] bytes = str.getBytes(java.nio.charset.StandardCharsets.US_ASCII); for (int i = 0; i < bytes.length; i++) { System.out.printf("%02X ", bytes[i]); } System.out.println(); }
Sample output:
41 42 43 44 30 31 20 30 33 20 30 30 20 38 30 20 30 30 20 30 37
Table of ASCII characters:
I will add JVisaInstrument methods to send bytes instead of a string.
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
You are welcome!
I added methods to write byte[]
instead of String
, please test it:
Let me know if you need help getting the new code.
Can you test the new method to write a byte[]
?
JVisa whether you can read and write 16-base data? can you give an example?