Yoctopuce Yocto-RS485-V2 Mode D'emploi page 161

Table des Matières

Publicité

program
helloworld;
{$APPTYPE CONSOLE}
uses
SysUtils,
Windows,
yocto_api,
yocto_serialport;
var
errmsg,line
: string;
serialPort : TYserialport;
slave,reg: integer;
res : TLongIntArray;
cmd :string;
val
: integer;
begin
// Setup the API to use local USB devices. You can
// use an IP address instead of 'usb' if the device
// is connected to a network.
if
(YRegisterHub('usb',
begin
writeln('RegisterHub error: '
halt;
end;
if (paramcount>1) then
serialPort :=
else
begin
serialPort := YFirstSerialPort();
if
(serialPort=nil) then
begin
writeln('No module connected (check
halt;
end;
end;
writeln('Please enter the MODBUS slave address
repeat
ReadLn(slave);
until (slave>0) and
writeln('Please select a Coil No (>=1), Input Bit No
writeln('Input Register No (>=30001) or Register No
writeln('No:
');
repeat
ReadLn(reg);
until
(reg
>=1) and
while (true)
do
begin
if (reg>=40001) then
else if (reg>=30001) then
1)
else if (reg>=10001) then
else
res := serialPort.modbusReadBits(slave, reg-1, 1);
val
:= res[0];
writeln('Current value:
write('Press ENTER to read again, Q to
if((reg
mod 30000)
write(':
');
readLn(cmd);
if
(cmd
='q') or
if
(cmd<>'') and
begin
val
:= strtoint(cmd);
if(reg >=
end;
end;
yFreeAPI();
end.
www.yoctopuce.com
errmsg)
<>
YAPI_SUCCESS)
+ errmsg);
YFindSerialPort(paramstr(1))
(slave<256);
(reg<50000) and
((reg
res := serialPort.modbusReadRegisters(slave, reg-40001,
res := serialPort.modbusReadInputRegisters(slave, reg-30001,
res := serialPort.modbusReadInputBits(slave, reg-10001,
'+inttostr(val));
<
10000) then write
(cmd
='Q') then
halt;
((reg
mod 30000)
<
30001) then
serialPort.modbusWriteRegister(slave, reg-30001,
else
serialPort.modbusWriteBit(slave, reg-1, val);
19. Utilisation du Yocto-RS485-V2 en Delphi
then
cable)');
(1...255)');
(>=10001+),');
(>=40001)');
mod
10000)<> 0);
quit');
(' or enter a new
value');
10000) then
1)
1)
val)
153

Publicité

Table des Matières
loading

Ce manuel est également adapté pour:

Yocto-rs232

Table des Matières