ADICON Support Forum Applied Digital, Inc.
Page 1 of 1 1
Topic Options
#13112 - 04/05/05 02:53 PM ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
I use ActiveX and I wish to change a variable in Ocelot. How I can to do it?
Top
#13113 - 04/06/05 01:07 AM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
I don't think the CMX ActiveX supports PutVariable, Viktor. It's easily done using the binary serial protocol but you would need to close the ActiveX to release the com port and provide your own comms routines.

If the ability to write a variable is essential, you may be better to use the older CMX.bas module ( http://www.appdig.com/Serprot/CExample.zip ). This module provides the necessary communications routines and it is simple to add an additional function to write a variable. I guess you would need to change it for Delphi, though, as it is written for VB6.

Top
#13114 - 04/09/05 02:34 PM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
Hello. I have started to write the program, I work with Ocelot, Secu-16, BobCat. I use CPU-XA Protocol (3, March 2000), but at me nothing turns out. Commands from this documentation do not work or work, but those as is written to documentation. Even the example which has been laid out on a site for Cbuilder, works not completely. I have established program Port Mon and have seen, that program CPUXA.exe sends such commands which are not present in the documentation:

43 0.00003017 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
327 0.00003157 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
511 0.00004107 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
701 0.00003073 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
884 0.00003380 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1068 0.00002905 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1253 0.00003101 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1436 0.00003213 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1621 0.00003073 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1804 0.00002933 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
1989 0.00002905 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
2173 0.00003213 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
2352 0.00003101 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 0F A9 00 36 CD
2529 0.00003017 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F A9 00 0D 97
2705 0.00003241 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F AA 00 58 C4
2887 0.00003269 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
3066 0.00003352 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 0F A9 00 36 CD
3243 0.00003101 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F A9 00 0D 97
3419 0.00003241 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F AA 00 58 C4
3603 0.00002933 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
3783 0.00003157 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 0F A9 00 36 CD
3960 0.00003185 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F A9 00 0D 97
4137 0.00003129 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8F AA 00 58 C4
4318 0.00002989 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
4502 0.00003017 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
4689 0.00002961 CPUXA.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9

Can I something not so do? How you write programs for Ocelot? Whether there Is a present documentation?

Top
#13115 - 04/09/05 04:21 PM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
Viktor, I have written my communications code following the CPU-XA protocol without any problem so I believe the document is correct. I will point out that the protocol shows decimal values for the command bytes - taking them as hexadecimal would give you a problem.

The commands shown by your monitor are type 42 (0x2A) which are generally used to read various blocks of memory from the controller. Most of your monitored commands (2A 00 00 8D B5 00 25 E9) are "Get Real Time I/O" which you will find on page 1 of the protocol.

Top
#13116 - 04/09/05 04:57 PM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
There is one important function that is not covered in the published protocol - reading variables from the controller. This is done by reading a memory block containing all 128 variables using a type 42 command. The location of the block may change with different firmware releases but its address can be read with another type 42 command. If you read through CMX.Bas you will see how this works.
Top
#13117 - 04/10/05 12:18 AM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
I have found the description of this function in the documentation.

Get Real Time I/O

->Send 8 binary bytes: <42> <0> <0> <141> <181> <0> <37> <233>
<-Receive 6 byte header:
<-Receive 256 bytes data: etc…
<-Receive 2 byte CRC

Note: You may have to program a short delay between sending the command and receiving the 264 byte response.

Data Explanation:
SECU 16, Type 11 Data1 = Real Time Input Bits 0-7
Data2 = Latched Relay Bits 0-7

SECU 16I, Type 12 Data1 = Real Time Input Bits 0-7
Data2 = Real Time Input Bits 8-15

RLY08-XA, Type 13 Data1 = 0
Data2 = Latched Relay Bits 0-7

I have some problems with it. Instead of return 264 symbols, it returns only 7. Log is:

101 0.00005503 Project1.exe IRP_MJ_CREATE Serial0 SUCCESS Options: Open
102 0.00000363 Project1.exe IOCTL_SERIAL_GET_BAUD_RATE Serial0 SUCCESS
103 0.00000196 Project1.exe IOCTL_SERIAL_GET_LINE_CONTROL Serial0 SUCCESS
104 0.00000168 Project1.exe IOCTL_SERIAL_GET_CHARS Serial0 SUCCESS
105 0.00000168 Project1.exe IOCTL_SERIAL_GET_HANDFLOW Serial0 SUCCESS
106 0.00000978 Project1.exe IOCTL_SERIAL_SET_BAUD_RATE Serial0 SUCCESS Rate: 9600
107 0.00000503 Project1.exe IOCTL_SERIAL_CLR_RTS Serial0 SUCCESS
108 0.00000475 Project1.exe IOCTL_SERIAL_CLR_DTR Serial0 SUCCESS
109 0.00000335 Project1.exe IOCTL_SERIAL_SET_LINE_CONTROL Serial0 SUCCESS StopBits: 1 Parity: NONE WordLength: 8
110 0.00000168 Project1.exe IOCTL_SERIAL_SET_CHAR Serial0 SUCCESS EOF:0 ERR:0 BRK:0 EVT:0 XON:0 XOFF:0
111 0.00000335 Project1.exe IOCTL_SERIAL_SET_HANDFLOW Serial0 SUCCESS Shake:0 Replace:8 XonLimit:0 XoffLimit:0
112 0.00000251 Project1.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge: RXCLEAR
113 0.00000168 Project1.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge: TXCLEAR
114 0.00000196 Project1.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge: RXABORT
115 0.00000196 Project1.exe IOCTL_SERIAL_PURGE Serial0 SUCCESS Purge: TXABORT
116 0.00003576 Project1.exe IRP_MJ_WRITE Serial0 SUCCESS Length 8: 2A 00 00 8D B5 00 25 E9
117 0.00000950 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: 2A
118 0.00000196 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: 8D
119 0.00000196 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: B5
120 0.00000168 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: BD
121 0.00000168 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: FF
122 0.00000168 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: 30
123 0.00000196 Project1.exe IRP_MJ_READ Serial0 SUCCESS Length 1: 3C
124 0.00000000 Project1.exe IRP_MJ_READ Serial0 Length 1

Code of the program is:

char command_to[200];
char buffer_from[500];
int size_buffer_from;
DWORD size_from;
unsigned char ch;
command_to[0]=42;
command_to[1]=0;
command_to[2]=0;
command_to[3]=141;
command_to[4]=181;
command_to[5]=0;
command_to[6]=37;
command_to[7]=233;

WriteFile(hPort, command_to, 8, &size_from, NULL);
size_buffer_from=0;
do{
ReadFile(hPort, &buffer_from[size_buffer_from], 1, &size_from, NULL);
size_buffer_from=size_buffer_from+ size_from;
}while(size_buffer_from < 264);

I didn’t include the block of opening com port.

Top
#13118 - 04/10/05 01:12 AM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
It looks like your command write is OK but I suspect you are failing to collect most of the returned bytes. Try reading the whole block of 264 bytes in one operation rather than one byte at a time. You may want to add a timeout mechanism in case you get no response. I use about 3 seconds but that is for use across a wireless network.
Top
#13119 - 04/10/05 01:51 PM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
[CODE]
void __fastcall TForm1::Button6Click(TObject *Sender)
{
DWORD tm;
unsigned char ch;
command_to[0]=42;
command_to[1]=0;
command_to[2]=0;
command_to[3]=141;
command_to[4]=181;
command_to[5]=0;
command_to[6]=37;
command_to[7]=233;

WriteFile(hPort, command_to, 8, &size_from, NULL);
tm=GetTickCount();
size_buffer_from=0;
while((size_buffer_from < 264)&&((GetTickCount()-tm)<3000)) // wait for response
{
ReadFile(hPort, &buffer_from[size_buffer_from], 264, &size_from, NULL);
size_buffer_from=size_buffer_from+ size_from;
}
}
[/CODE]I have changed the program, but nothing has changed. The example with my program lays in self-unpacked archive:
smarthouse.rostov.ru/temp/CMAX_Sample1.exe

What else can I to make?

Top
#13120 - 04/10/05 03:12 PM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
Viktor, I could not extract any source from your archive. Perhaps it would be better as a Zip?

The next thing to check is that the Com Port is opened correctly. This should be for 9600 Baud, No Parity, 8 Databits, 1 Stopbit. The receive buffer should be greater than 264 bytes. Handshaking should be off. DSR and CTS will not be asserted by Ocelot. You should also check that nulls are not being stripped - there are a lot of zero bytes in most Ocelot responses.

Top
#13121 - 04/11/05 05:14 AM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
The port opens correctly. I have made zip archive with the program and have laid out to this address: smarthouse.rostov.ru/temp/CMAX_Sample1.zip
Top
#13122 - 04/11/05 08:04 AM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
Viktor, this time I can see your source files. I cannot run your program directly because I do not have the C++ Builder IDE. The code should be similar to Visual C++ 6.0, though, so I suggest the following:

You have set dcb.fNull = TRUE. This should be FALSE to allow zero bytes to be received.

The following flags should all be FALSE:
dcb.fOutxCtsFlow
dcb.fOutxDsrFlow
dcb.fDsrSensitivity
dcb.fOutx
dcb.fInx

Also dcb.fBinary should be TRUE but I think that is the default.

Try also setting dcb.fAbortOnError to FALSE - at least until you get it working!

Top
#13123 - 04/11/05 10:02 AM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
The program works!!! Many thanks. Today was a good day.
Top
#13124 - 04/11/05 10:02 AM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
The program works!!! Many thanks. A good day was today.
Top
#13125 - 04/11/05 11:23 AM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
That is great news, Viktor. I know how it feels when a piece of software finally starts to work.

One small warning about changing Ocelot variables from your PC: The new value will take effect immediately not at the start of the next program cycle. This can give unexpected results...

Top
#13126 - 04/15/05 03:41 PM Re: ActiveX & Put Variable
Bykov Viktor Offline
newbie


Registered: 08/27/04
Posts: 17
Loc: Russia, Rostov-on-Don
I have finished development of the basic functions.
smarthouse.rostov.ru/temp/OcelotMaster.exe
Now I shall develop the user program.
Already 2:47 mornings.

Top
#13127 - 04/15/05 04:46 PM Re: ActiveX & Put Variable
Rex Offline
active contributor


Registered: 09/15/04
Posts: 106
Loc: UK
Viktor, I cannot run your code on my PC - it needs vcl60.bpl. Would that be the runtime for C++ Builder?

I'm happy to hear that your code development is going well - even if you are missing some sleep. It's a funny thing - I also find that I write my best software in the middle of the night.

Top
Page 1 of 1 1


Moderator:  Dan Smith, Monte G, ADI Tech Support, Guy Lavoie 
Hop to:
Who's Online
0 registered and 60 anonymous users online.
Recent Posts
Ocelot Battery
by ADI Tech Support
09/22/17 07:38 AM
Comms Retry Error
by HDTVPete
09/18/17 04:04 PM
Cmax Message: Failed to set data for a 'delay'
by HDTVPete
09/16/17 04:36 PM
Shout Box

Newest Members
brigiel, vevevie, zhutree, 416, saiqul
3003 Registered Users
Forum Stats
3003 Members
19 Forums
4002 Topics
23435 Posts

Max Online: 132 @ 11/13/16 10:07 AM
September
Su M Tu W Th F Sa
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30