LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Pascal code to labVIEW vi

I have some Pascal code writen for an 8bit Serial ADC circuit. I have had a look at the Pascal code and I made an attemp at implementing it in labVIEW but obviously it didnt work.

The Pascal code writes/reads to the DTR, RTS and CTS lines which I was able to do with little success, I used the property node and chose 'modem line settings' which gave me the options to write to the lines i mentioned above. The problem is with the way the Pascal code addresses the different lines. If you look at the Const: in the pascal code, it consists of the combase add, the MCR(DTR) add, LCR(RTS) add and the MSR(CTS) add, how can I do that in LabVIEW because the open visa session vi only allows you to specify visa resource name e.g. asrl1::instr etc.

the other thing I don't understand is the 1st and 3rd line in the 'for loop' of the Pascal code. how can I implement the 3rd line? Another thing is that the Pascal code sets the MCR(DTR) line to an integer value 3 which when I do in labVIEW comes up with an error, it only allows me to write either 1 or 0?? Can anyone help by telling me where to start from? Below is the Pascal code. I have attached my current vi which does not work.

the circuit diagram for the 8bit adc can be found here...
http://www.hut.fi/Misc/Electronics/circuits/ad_serial.html

Pascal Code........

Program serial_adc;

Uses Crt;

Const
combase=$3f8; { I/O address of the COM port you are using }
MCR=combase+4;
LCR=combase+3;
MSR=combase+6;

Procedure Initialize_converter;
Begin
Port[MCR]:=3; { make DTR line to supply power and set CS input of chip to 1 }
Port[LCR]:=0; { set clock line of the chip to 0 }
End;

Function Read_value:byte;
Var
value:byte;
count:byte;
Begin
value:=0;
Port[MCR]:=1; { set CS down }
For count:=0 to 7 Do Begin { do the bit value eading 7 times }
value:=value SHL 1; { value=2*value }
Port[LCR]:=64; { clock line up }
If (port[MSR] and $10)=$10 Then Inc(value); { read the input data and update value }
Port[LCR]:=0; { clock line down }
End;
Port[MCR]:=3; { set CS up again }
Read_value:=value; { return the value }
End;

Begin
Initialize_converter; { call initialization routine }
Repeat
Writeln(Read_value); { call reading routine and print the value }
Delay(1200);
Until KeyPressed; { repeat until any key is pressed }
End.
.........

thanks a lot
Bupe
0 Kudos
Message 1 of 5
(3,798 Views)
Rather than use VISA, you might consider using the Port I/O functions. This would make for a more straightforward translation of your program.

Brian
0 Kudos
Message 2 of 5
(3,798 Views)
Using the inport and outport vi's was a good idea because I did get a response from the circuit. This is what I have done so far(see attachment). From running the VI, I can see that it does actually communicate with my circuit but the results I am getting are not as expected and I know that the problem is with the way I handle what I read from the port. Anding the results from the inport vi with 0x10 produces a boolean result that I am not sure what to do with.

Any idea of how I should handle this line in my vi?

"If (port[MSR] and $10)=$10 Then Inc(value); { read the input data and update value }"

Thanks.
0 Kudos
Message 3 of 5
(3,798 Views)
You can use the "And" function with integer inputs. One of the inputs comes from InPort, and the other is a constant hex 0x10. The result of the "And" will also be a numeric. You can test this result with the "=0?" function. If the result is zero, you do nothing. If the result is non-zero, you know the 0x10 bit must have been set. So, you'll then increment your "value" as in the code above.

Does this make sense?

Brian
0 Kudos
Message 4 of 5
(3,798 Views)
mad props to you Brian, you really did give me something to work with. The idea of using the inport vi's was really great as I mentioned and I am glad to say that I got my code to work and read from my circuit.

The line that reads

'if (port[MSR] AND $10)=$10 then inc(value)'

was what puzzled me and now I realised that it means read whats on that particular address port[MSR] then AND it with hex value 0x10 and if the results of the operation is equal to '0x10 or (16 Decimal)' then increment the value (the MSB is set) else do nothing. Thanks again for pointing me in the right direction.

I still don't get how this actually works (gets the actual value) but looking at the code I did, I know exactly how it runs and what it does.

T
hanks again, i owe you some stars...

Bupe
0 Kudos
Message 5 of 5
(3,798 Views)