Program Hai
Program Hai
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Motor
//AM600
ELEM_QX = 0, //QX 元件
ELEM_MW = 1, //MW 元件
//H3U
REGI_H3U_SD = 0x2b, //
REGI_H3U_R = 0x2c, //
//H5u
class Program
public static extern bool Init_ETH_String(string sIpAddr, int nNetId = 0, int IpPort = 502);
public static extern int H3u_Write_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount,
byte[] pValue, int nNetId = 0);
public static extern int H3u_Read_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount, byte[]
pValue, int nNetId = 0);
public static extern int H3u_Read_Soft_Elem_Float(SoftElemType eType, int nStartAddr, int nCount,
float[] pValue, int nNetId = 0);
public static extern int H5u_Write_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount,
byte[] pValue, int nNetId = 0);
public static extern int H5u_Read_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount, byte[]
pValue, int nNetId = 0);
public static extern int H5u_Read_Soft_Elem_Float(SoftElemType eType, int nStartAddr, int nCount,
float[] pValue, int nNetId = 0);
public static extern int H5u_Read_Device_Block(SoftElemType eType, int nStartAddr, int nCount,
byte[] pValue, int nNetId = 0);
[DllImport("StandardModbusApi.dll", EntryPoint = "Am600_Write_Soft_Elem", CallingConvention =
CallingConvention.Cdecl)]
public static extern int Am600_Write_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount,
byte[] pValue, int nNetId = 0);
public static extern int Am600_Read_Soft_Elem(SoftElemType eType, int nStartAddr, int nCount,
byte[] pValue, int nNetId = 0);
string ip = args[1];
int[] position_sensor = { 1, 2, 4 };
if (!result)
{
value_result = "FAIL -1 CONNECT_ERROR";
Console.WriteLine(value_result);
//Console.WriteLine("failed to init.");
return 255;
if (args[0] == "CHECK_ROTATE")
int dir_value;
int present_index = 0;
int next_index = 0;
if (next_position_flag)
next_position_flag = false;
if (updown_relay_value == 0)
break;
else if (updown_relay_value == 1)
if (sensor_value == 0) continue;
if (first_sensor_value == -1)
first_sensor_value = sensor_value;
present_index = Math.Log(sensor_value,2);
next_position_flag = true;
count_round += 1;
continue;
if (sensor_value == position_sensor[present_index])
break;
next_position_flag = true;
present_index = next_index;
else break;
Console.WriteLine(value_result);
//writeCommand(100, 2);
int value;
while (true)
{
Thread.Sleep(5);
Exit_ETH(int.Parse(args[2]));
return 0;
Debug.WriteLine(String.Format("H5u_Read_Soft_Elem:{0}", nValue));
return nValue;
//{
// {
// Console.WriteLine("failed to init.");
// return 255;
// }
// int[] position_sensor = { 1, 2, 4 };
// if (args[0] == "ROTATE_CHECK_DIR")
// {
// }
// {
// writeCommand(100, 2);
// }
// //{
// // writeCommand(100, 1);
// //}
// // writeCommand(100, 2);
// //}
// //{
// // writeCommand(110, 1);
// //}
// //{
// // writeCommand(110, 2);
// //}
// //{
// // writeCommand(130, 1);
// //}
// //{
// // writeCommand(130, 2);
// //}
// //{
// // writeCommand(150, 1);
// //}
// //else if (args[0] == "RELAY-OFF")
// //{
// // writeCommand(150, 2);
// //}
// //{
// // writeCommand(600, 1);
// //}
// //{
// // writeCommand(500, 1);
// // Thread.Sleep(500);
// // int v = int.Parse(args[4]);
// // writeCommand(350, v);
// // Thread.Sleep(500);
// // writeCommand(500, 0);
// //}
// //{
// // writeCommand(500, 1);
// // Thread.Sleep(500);
// // int v = int.Parse(args[4]);
// // writeCommand(450, v);
// // Thread.Sleep(500);
// // writeCommand(500, 0);
// //}
// //{
// //}
// //{
// //}
// //{
// //}
// //{
// //}
// //{
// // writeCommand(120, 1);
// // writeCommand(120, 0);
// //}
// //{
// // writeCommand(120, 1);
// // //writeCommand(120, 0);
// //}
// //else if (args[0] == "CHECK-ROTATE")
// //{
// // writeCommand(120, 0);
// //}
// //{
// // Thread.Sleep(500);
// // writeCommand(120, 2);
// //}
// Exit_ETH(int.Parse(args[2]));
// if (result)
// Console.WriteLine("pass");
// else
// Console.WriteLine("fail");
// return 0;
//}
//{
// int nNetId = 0;
// pValue = BitConverter.GetBytes(value);
// int nRet = H5u_Write_Soft_Elem(SoftElemType.REGI_H5U_D, Addr, 2, pValue, nNetId);
// //Console.WriteLine(String.Format("(checkStatus) nRet:{0}",nRet));
//}
//{
// int nNetIdR = 0;
// {
// Debug.WriteLine(String.Format("H5u_Read_Soft_Elem:{0}", nValue));
// if (nValue == value)
// return true;
// }
// return false;
//}
//{
// int nNetIdR = 0;
// int durationStart = Environment.TickCount;
// {
// Debug.WriteLine(String.Format("H5u_Read_Soft_Elem:{0}", nValue));
// if (nValue == value)
// return true;
// }
// return false;
//}
//{
// int nNetIdR = 0;
// int nRet = 0;
// {
// if (nRet == 1)
// return true;
// }
// return false;
//}
//{
// int nNetIdR = 0;
// {
// Debug.WriteLine(String.Format("H5u_Read_Soft_Elem:{0}", nValue));
// if (nRet == 1)
// return true;
// }
// return false;
//}