pfroud / JVisa

Java library for VISA (Virtual Instrument Software Architecture) instruments
Apache License 2.0
42 stars 14 forks source link

JVisa whether you can read and write 16-base data? #14

Closed Rx-out closed 5 months ago

Rx-out commented 7 months ago

JVisa whether you can read and write 16-base data? can you give an example?

pfroud commented 7 months ago

Please give an example of what you want to do

Rx-out commented 7 months ago

1710313464977

send hexadecimal data device

pfroud commented 7 months ago

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:

ASCII table

I will add JVisaInstrument methods to send bytes instead of a string.

Rx-out commented 7 months ago

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: @.***>

pfroud commented 7 months ago

You are welcome!

I added methods to write byte[] instead of String, please test it:

https://github.com/pfroud/JVisa/blob/7d018d4218004dd44b5128cc1340bc135475c7c7/src/main/java/xyz/froud/jvisa/JVisaInstrument.java#L207

Let me know if you need help getting the new code.

pfroud commented 7 months ago

Can you test the new method to write a byte[]?