private void buttonApply_Click(object sender, EventArgs e) { hapondPrintParam.Flag = new char[] { 'H', 'A', 'P', 'D' }; for (int i = 0; i < hapondPrintParam.MotorTors.Length; i++) { MotorTorParam motorTorParam = hapondPrintParam.MotorTors[i]; if (i == 2 || i == 3) { motorTorParam.mode = (byte)modeBoxs[i].SelectedIndex; } else { motorTorParam.mode = 1; } motorTorParam.dir = (byte)dirBoxs[i].SelectedIndex; motorTorParam.value = (ushort)values[i].Value; hapondPrintParam.MotorTors[i] = motorTorParam; } byte[] buf = PubFunc.StructToBytes(hapondPrintParam); uint len = (uint)buf.Length; int ret = CoreInterface.SetEpsonEP0Cmd(0x92, buf, ref len, 0, 0x0100); if (ret == 0) { MessageBox.Show("应用电机参数失败!"); } }
/// <summary> /// 1。设置Parameter /// 通过USB EP0。方向是OUT。 /// reqCode是0x7F。value是2,setuplength是长度,一次操作的长度不能超过64Byte。 /// 写失败会报STATUS_FTA_EEPROM_WRITE. /// 增加Index值,index为0 是allwin清洗参数。index为1是MIC清洗参数。 /// </summary> /// <returns> /// The set MIC clean parameter. /// </returns> private bool SetMICCleanParameter() { byte[] subval = PubFunc.StructToBytes(this.getCleanParameter()); byte[] Buf = new byte[64]; uint bufsize = (uint)Buf.Length; Buffer.BlockCopy(subval, 0, Buf, 0, Buf.Length); ushort index = (ushort)((this.comboBoxCleanMode.SelectedIndex << 8) + 1); if (CoreInterface.SetEpsonEP0Cmd(0x7F, Buf, ref bufsize, 2, index) == 0) { MessageBox.Show("设置MIC清洗Parameter失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } byte[] Buf1 = new byte[subval.Length - 64]; Buffer.BlockCopy(subval, Buf.Length, Buf1, 0, Buf1.Length); index = (ushort)((this.comboBoxCleanMode.SelectedIndex << 8) + 2); bufsize = (uint)Buf1.Length; if (CoreInterface.SetEpsonEP0Cmd(0x7F, Buf1, ref bufsize, 2, index) == 0) { MessageBox.Show("设置MIC清洗Parameter失败!", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(true); }
/// <summary> /// 初始化共享内存 /// </summary> /// <param name="strName">共享内存名称</param> /// <param name="lngSize">共享内存大小</param> /// <returns></returns> public int Init(string strName, long lngSize) { if (lngSize <= 0 || lngSize > 0x00800000) { lngSize = 0x00800000; } m_MemSize = lngSize; if (strName.Length > 0) { //创建内存共享体(INVALID_HANDLE_VALUE) m_hSharedMemoryFile = CreateFileMapping(INVALID_HANDLE_VALUE, IntPtr.Zero, (uint) PAGE_READWRITE, 0, (uint)lngSize, strName); if (m_hSharedMemoryFile == IntPtr.Zero) { m_bAlreadyExist = false; m_bInit = false; return(2); //创建共享体失败 } else { if (GetLastError() == ERROR_ALREADY_EXISTS) //已经创建 { m_bAlreadyExist = true; } else //新创建 { m_bAlreadyExist = false; } } //--------------------------------------- //创建内存映射 m_pwData = MapViewOfFile(m_hSharedMemoryFile, FILE_MAP_WRITE, 0, 0, (uint)lngSize); if (m_pwData == IntPtr.Zero) { m_bInit = false; CloseHandle(m_hSharedMemoryFile); return(3); //创建内存映射失败 } else { m_bInit = true; if (m_bAlreadyExist == false) { //初始化 MyData data = new MyData(-1); byte[] bd = PubFunc.StructToBytes(data); Marshal.Copy(m_pwData, bd, 0, bd.Length); } } //---------------------------------------- } else { return(1); //参数错误 } return(0); //创建成功 } //end fun
private int SetSinglePassYaTaoFactoryParam(SinglepassYataoFactoryParam param) { byte[] buf = PubFunc.StructToBytes(param); uint bufsize = (uint)buf.Length; int ret = 0; //modify by ljp 2014-5-20 if (listBox1.SelectedIndex < 0) { ret = CoreInterface.SetEpsonEP0Cmd(0x7b, buf, ref bufsize, 0, 1); } else { int mbid = (int)listBox1.Items[listBox1.SelectedIndex]; ret = CoreInterface.SetEpsonEP0Cmd(0x7b, buf, ref bufsize, 0, 1, mbid); } return(ret); }
} //end fun /// <summary> /// 设置共享内存(MyData结构) /// </summary> /// <param name="str"></param> /// <returns></returns> public static bool SetShareMem(MyData data) { int MemSize = Marshal.SizeOf(typeof(MyData)); if (Data.Init("MyData", MemSize) != 0) //"MyData"共享内存名称,您起别的名字也可以 { return(false); } try { byte[] b = PubFunc.StructToBytes(data); Data.Write(b, 0, b.Length); } catch (Exception) { return(false); } return(true); } //end fun