Сообщение от
alfdivn
Мы используем АС3 конвертер.
В качестве приемника выступает 1С
owen_io.dll завернута через visual studio c# в dll, добавлены классы, чтобы 1С могла ее подключать
для общения через owen_io.dll созданы 3 класса
OPCStartConnect(num) // открывает порт
OPCReadData(adress,typedata,namevar) // читает данные
OPCEndConnect(void) // закрывает порт
вот класс для чтения данных (нужное имя я передаю цифрой, а то у 1С и C# нестыковка в текстовых переменных)
public string OPCReadData(int Address, int typeD, int NameD)
{
float value=0;
int dcnt = 0;
int dcnt1 = 0;
int timestamp = 0;
float dataM = 0;
string ret;
string[] nameS = new string[10];
nameS[0] = "DCNT";
nameS[1] = "Rd.pF";
nameS[2] = "DSPD";
nameS[3] = "Ctr";
nameS[4] = "CEU";
IntPtr name = Marshal.StringToCoTaskMemAnsi(nameS[NameD]);
if(typeD == 0)
{
res1 = NativeMethods.ReadSI8BCD(Address, 0, name,ref dcnt);
dataM = dcnt;
}
if(typeD == 1)
{
res1 = NativeMethods.ReadIEEE32(Address, 0, name, ref value, ref timestamp, -1);
dataM = value;
}
if(typeD == 2)
{
res1 = NativeMethods.ReadSInt(Address, 0, name, ref dcnt, -1);
dataM = dcnt;
}
if(typeD == 3)
{
res1 = NativeMethods.ReadUInt(Address, 0, name, ref dcnt1, -1);
dataM = dcnt1;
}
if (res1 == 0)
ret = Convert.ToString(dataM);
else
ret = Convert.ToString(res1);
return ret;
}
Это кусок кода в 1С, как бы все просто, открыл, считал, закрыл....
OPCconnect = Новый COMОбъект("COMobjOPC.COMOCR");
аб = OPCconnect.OPCStartConnect(1); // открываем порт (номер COM порта)
..............
ЦИКЛ (пока не остановится траверса)
.............
ЗначениеДатчика = OPCconnect.OPCReadData(АдресДатчика,ТипДанных,ИмяП еременной);
.............
КОНЕЦЦИКЛА
OPCconnect.OPCEndConnect();