LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

hexadecimal versus octal via serial port

Hi all,

sorry guys i actually duplicated this post because i did not get the best answer i want. so sorry 🙂

 

 

I have a small application that consists of reading data from a serial port using VISA READ function. The source of data that i am trying to acquire from the serial port is a microcontroller that is sending a word or a byte( 8bits) . However, when trying to download the programming code into the microcontroller, the programming software saves the code as HEX file in the chip. That was all just an explanation to get into the problem. in oreder to get my application done, i used the attached VI which i did not program but added some functions to it for many purposes.The Vi is working perfectly and everything is working well, but it seems that i got some misunderstanding right here. what i am trying to understand right here is why a (hexadecimal string to number) function is used as long as i configured everything to read bytes( 8bits) I am very confused any suggestions would be appreciated.

 

 

Thank you

Bill David
Download All
0 Kudos
Message 1 of 17
(3,028 Views)

You now attached the same VI four times (twice here and twice here). What makes you think that posting the same question again will give you new insight, especially since you marked the old thread as solved? Is it solved or is it not solved? To keep the forum organized, you could have simply added new (if any) information to the end of your old thread.

 

Everything is bytes one way or another, so the correct function depends on the structure of the received string. Apparently the bytes form a hexadecimally formatted integer value, consisting of two letters between 00 and FF. After conversion to a numeric integer, it is divided by 255, because that's how the scale is defined: 0 (00) is zero volts while a number of 255 (FF) will give you a DBL value corresponding to the configured "MaxVoltage". There is no magic or hidden meaning. You simply need to read the documentation that comes with the instrument and code accordingly.

 

 

 

0 Kudos
Message 2 of 17
(3,023 Views)

Dear 

 

first i wanna say that i am very sorry for duplicating the post here and there. but it's all because i got a misunderstanding with the explanation of some function of the attached VI 

 

 

you said, and i agree with you that bytes form a hexadecimal representation .but if you take a look at the front panel of the VI you will see that data bits are configured to be 8 bits so i am dealing with a byte (8 bits) .

 

 

are you saying that this VI takes every 2 bytes together as a hexadecimal value and translate them into  numbers by splitting them into byte(8bit) again by dividing them into 255 ?

 

Bill David
0 Kudos
Message 3 of 17
(3,016 Views)

@Bildavid wrote:

you said, and i agree with you that bytes form a hexadecimal representation .but if you take a look at the front panel of the VI you will see that data bits are configured to be 8 bits so i am dealing with a byte (8 bits) .


This is your serial port configuration, that descibes how the data is encoded. This simply needs to match the configuration at the other end or you get garbage. It does not tell you how many bytes arrive at the serial port or anything about the transported data.

 


@Bildavid wrote:

are you saying that this VI takes every 2 bytes together as a hexadecimal value and translate them into  numbers by splitting them into byte(8bit) again by dividing them into 255 ?


The VI takes whatever "data" is received and treats it as a spreadsheet string with hexadecimal fields and spaces as delimiter, then forms an array of strings containing one element per hexadecimally formatted field. Each element is scanned into a U32 numeric, forming a numeric array, then divided by 255 and multiplied by the max voltage. There is no "splitting" into bytes per se. Without seeing the raw string, we don't know how may butes there are per value. Since he scans it into a U32, it could be up to 8 hexadecimal characters per field. We cannot tell.

(btw: the inner FOR loop can be removed without change in functionality because all contained operations can work on arrays directly)

 

Why are you asking all these questions. All you need to do is look at the "received string". I cannot see it because I don't have your hardware! This program has probably not been written by an expert programmer, otherwise it would have some diagram comments describing the format of the received string.

 

For further analysis, we need to see the received string. Can you run the VI, then copy whaever you get in the "read string" indicator?

0 Kudos
Message 4 of 17
(3,011 Views)

okay here is the image that i took while running the VI 

 

 

thank you for trying to help

 

Bill David
0 Kudos
Message 5 of 17
(3,004 Views)

OK, you you get 10 bytes of binary data. The code makes no sense in this respect, because it is not hexadecimally formatted, space delimited text.

 

Do you have documentation on the instrument that is sending the data? Are you sure the program actually works correctly?

0 Kudos
Message 6 of 17
(2,989 Views)

Dear 

 

Yes the program works correctly . the device (hardware) that is sending the signal is an ECG amplifier that detects the electrical impulses of the human heart and as you can see the heart signal waveform is very clear .

 

to be more specific i have designed an ecg amplifier which output an analogue signal . this analogue signal should be digitized in order to be sent to the PC.

for the conversion from analogue to digital i have used the microcontroller 16F874 from microchip. this is why i was wondering why the hexadecimal to number function is used. because the internal A/D of the microcontroller has an 8 bits representation. 

Besides, the microcontroller is used here also to establish the serial connection by connecting the output of the microcontroller to the max232 and then to the DB9 female.

 

i hope i made the idea clear.

 

Thank you very much 

Bill David
0 Kudos
Message 7 of 17
(2,958 Views)

Showing us a picture of a DB-9 connector is pointless. What information does this add? It appears to me that the VI you posted was written by someone else and you are trying to use it with your own implementation of the serial communication in the microcontroller. That VI was written assuming that the other end sent character data with values separated by spaces, and terminated with a linefeed. Your implementation of the serial communication is not doing that. You are sending raw bytes. So clearly this will not work. You either have to change the LabVIEW code, or you have to change the microcontroller code to send the information the way the VI expects it. Which do you want to do? We can't tell you how to change the LabVIEW code unless you provide explicit details on the format of the data that the microcontroller is sending. If you not capable of figuring that out, then post the microcontroller code.

0 Kudos
Message 8 of 17
(2,942 Views)

Dear 

 

Yes the VI that was attached in the previous posts was made by someone else and i am trying to use in my application. well thank you for trying to give some help here .

Dear friend i am gonna explain in details what do i want to do .

 

i have designed an ECG amplifier which detects the heart signal . so we call it an ECG sensor like like those you can find in any hospital

 

the output of the ECG sensor is an analogue signal . so i have connected this analogue signal to the microcontroller 16F874 (from microchip) in order to do the following:

 

 do the analogue to digital conversion

 send the digitized signal serially by connecting the output of microcontroller to a MAX232 and then to a db9 connector.

 

the internal A/D of the microcontroller has an 8 bits resolution.

 

well to be more precise here is the programming code of the microcontroller

 

#INCLUDE         "P16F874A.INC"

         

          CBLOCK  0X20

          A1

          ENDC

 

          ORG          0X000

          GOTO                 MAIN

MAIN

          CALL                  SETUP

          CALL                  SETUP_USART

REP

          CALL                  A2D_CHANEL_0

          GOTO                 REP

 

A2D_CHANEL_0

          MOVLW   B'01000001'

          MOVWF    ADCON0

          CALL                  A2D_DELAY

          BSF            ADCON0,GO

          BTFSC                ADCON0,GO

          GOTO                 $-1

          MOVF                 ADRESH,W

          MOVWF    TXREG

          RETURN

 

A2D_DELAY

          MOVLW             D'5'

          MOVWF             A1

          DECFSZ              A1,F

          GOTO                           $-1

          RETURN

 

SETUP

          CLRF                  PORTA

          CLRF                  PORTB

          BSF            STATUS,RP0

          MOVLW   B'00001110'

          MOVWF    ADCON1

          BSF            TRISA,0

          BCF            STATUS,RP0

          RETURN

 

SETUP_USART

          BSF            STATUS,RP0

          BCF            TRISC,6

          MOVLW   B'00100100'

          MOVWF    TXSTA

          MOVLW   D'12'

          MOVWF    SPBRG                ;19200 BAUDE RATE SELECTION

          BCF            STATUS,RP0

          MOVLW   B'10010000'

          MOVWF    RCSTA

          BSF            INTCON,PEIE

          BSF            INTCON,GIE

          RETURN

 

          END

 

I hope that i made the point clear 

again thank you .

 

any suggestions would be appreciated

 

 

 

 

 

Bill David
0 Kudos
Message 9 of 17
(2,937 Views)
Back in August, I suggested you use a string to byte array. You said you would try that. Why didn't you? Why are you asking the exact same question again and again?
0 Kudos
Message 10 of 17
(2,930 Views)