Page 1 of 1

Code for ZX-328n Working as slave of a PC with VB6

Posted: 11 October 2009, 13:18 PM
by vesteve
I am new with Z Processors and some idea programming in VB6.
I need to use a Zn-128 as interface to control a machine.
PortB will be used as output (Reles, light, etc...)
PortD will be used as Digital Input as Buttons, etc...
PortC will be used as A/D Reader for Temperature, Humidity, etc..
The Main program will be made by VB6, I will use the power of PC to store values, display, control, etc..
And, This is my question:
How Can I Get the values of PortC and PortD into VB6 variables?
How I can write values into PortB from VB6 variable?

Maybe you will consider these questions very child, but I have never work with RS232. :oops:

Thanks for your attention.

Posted: 11 October 2009, 14:22 PM
by dkinzer
There is no "standard" way to do what you've described. Essentially, you have to invent a protocol for sending data back and forth between the PC and the ZX. For example, you might send data to the PC in the form

Code: Select all

<element name> = <value> CRLF
where <element name> is a sequence of characters to identify the element whose value you're sending and <value> represents the value itself. (CRLF is a carriage return/linefeed combination.) The value could be in decimal form, hexadecimal form, real number form, logic form (e.g. TRUE or FALSE), symbolic form or any other form you find useful.

Once you've decided on the format, the only thing left to do is the coding. An Internet search will produce quite a bit of information on the subject of sending and receiving data in VB6 via the serial port.

Posted: 11 October 2009, 21:03 PM
by stevech
That's also called tagname/value

kind of like XML

Posted: 12 October 2009, 4:54 AM
by vesteve
OK, thats I was thinking about the way to work.
But One question.
Do I must open the RS232 in both PC and ZN?
And keep in both in receiving data?
An when have an interrupt as button, etc, or controlled by time, then send the new values from one to another by rs232?

Posted: 12 October 2009, 11:37 AM
by dkinzer
vesteve wrote:Do I must open the RS232 in both PC and ZN?
In order to send data on a serial channel on a ZX device, the serial channel must be open. The Com1 channel is opened automatically (at 19.2K baud) and you can send data most easily by using Debug.Print or Console.Write. If you want to use other serial channels (e.g. Com3 through Com6) you must define the configuration (DefineCom), initialize the queues (OpenQueue) and then open the serial channel (OpenCom). Once that is done, you send data by adding it to the channel's transmit queue.

On the PC side, you'll need to open a serial channel before you can use it. How that is done depends on whether you're using some VB code that someone else wrote or you're using the Windows system calls directly. Again, an Internet search will provide lots of information on this topic.
vesteve wrote:An when have an interrupt as button, etc, or controlled by time, then send the new values from one to another by rs232?
You can implement a strategy where the ZX only sends data when requested by the PC. Alternately, you can implement a strategy where the ZX sends data periodically or immediately when it becomes available. You can also implement a mixed strategy where some data is sent only on demand while other data is sent based on the occurrence of an event.