2.13 Communications with a Windows PC (Visual C++ Application)
Using Automatic Reception with the MP3000 as a Slave
2-348
// Get the PC’s port number.
// Add code to get the port number from TextBox5. Example: MyPort: 10001
// Get the MP3000’s IP address
// Add code to get the IP address from TextBox6, TextBox7, TextBox8, and TextBox9.
Example: DstIP: 0x0101A8C0
// Get the MP3000’s port number.
// Add code to get the port number from TextBox10.
Example: DstPort:
10001
// Get the connection type
// Add code to process the connection type selected in ComboBox1.
// Example: TransPort: TCP (0) *UDP (1)
// Open a TCP/UDP port
rc = memobus_master_main(TransPort, MyIP, MyPort, DstIP, DstPort)
∗
∗
}
private: System::Void Command2_Click(System::Object ∗ sender, System::EventArgs ∗ e)
{
// Add code to start a 100-ms timer
}
private: System::Void Command3_Click(System::Object ∗ sender, System::EventArgs ∗ e)
{
// Add code to stop the timer
}
// The following process starts the Timer and executes every 100 ms
private:System::XXXXX( )
{
unsigned char SFC = &H9 // Reads the contents of hold registers (extended).
unsigned char CPUNum = 1 // Set the remote device as CPU1
unsigned short Adr = 0 // Set the first address to MW00000
unsigned short DataNum = 10 // Read 10 words from the first address
// Create Extended MEMOBUS send data
MkCmdData(SFC, CPUNum, Adr, DataNum, Ssbuf)
// Send Extended MEMOBUS command and receive response
rc = MemobusMsg(TransPort, Ssbuf, Srbuf)
∗
∗
// Reflect values in the register monitor
// Add code to display the read register values
}
∗
∗
∗
}