public Form1() { InitializeComponent(); DeviceInterfaceDll.EventConnect += OnConnected; DeviceInterfaceDll.EventLogin += OnLogin; DeviceInterfaceDll.SR_Init(this, 0, 8877); string exename = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase; string path = System.IO.Path.GetFullPath(exename); string txtfile = path + "..//readme.txt"; //FileStream fs = File.OpenRead(txtfile); //fs.readline if (System.IO.File.Exists(txtfile)) { StreamReader sr = new StreamReader(txtfile); string lines = sr.ReadToEnd(); textBox5.Text = lines; tabControl1.SelectedTab = tabPage1; } comboBox1.SelectedIndex = 0; uint ver = DeviceInterfaceDll.SR_GetVersion(); uint verh = (ver & 0xff000000) >> 24; uint verm = (ver & 0xff0000) >> 16; uint verl = (ver & 0xffff); string s = string.Format("(dll ver:V{0:d}.{1:d}.{2:d})", verh, verm, verl); this.Text = this.Text + s; }
private void Button3_Click(object sender, EventArgs e) { if (comboBox2.Text == "") { MessageBox.Show("please select the user id first."); return; } uint id = Convert.ToUInt32(comboBox2.Text); uint ret = DeviceInterfaceDll.SR_GetCapacity(id, out DeviceInterfaceDll.SDInformation scobj); if (ret == DeviceInterfaceDll.RC_OK) { listView2.Items.Clear(); label4.Text = scobj.totalCapacity.ToString() + " MB"; label5.Text = scobj.surplusCapacity.ToString() + " MB"; //foreach (DeviceInterfaceDll.FileList fs in scobj.audioFileList) for (int i = 0; i < scobj.audioFileList.Length; i++) { ListViewItem ls = listView2.Items.Add((i + 1).ToString()); ls.SubItems.Add(scobj.audioFileList[i].fileName); ls.SubItems.Add(scobj.audioFileList[i].fileSize.ToString()); } } else { MessageBox.Show("read information of sd is fault."); } }
private void button2_Click(object sender, EventArgs e) { if (comboBox3.Text != null) { uint userid = Convert.ToUInt32(comboBox3.Text); uint ret = DeviceInterfaceDll.SR_Logout(userid); } }
private void Button7_Click(object sender, EventArgs e) { if (comboBox5.Text == "") { MessageBox.Show("please select the user id first."); return; } uint userid = Convert.ToUInt32(comboBox5.Text); DeviceInterfaceDll.SR_SetVolume(userid, (uint)numericUpDown2.Value); }
private void EmergencyFilePlayThread(Object arg) { uint sHandle = 0; uint ret; ThreadParam ap = (ThreadParam)arg; WorkProcessHandler h = new WorkProcessHandler(EmergencyFilePlayProcess); try { ret = DeviceInterfaceDll.SR_Emergency(out sHandle, ap.userid); if (ret == DeviceInterfaceDll.RC_OK) { int offset = 0; byte[] dat = new byte[640]; short[] pcm = new short[320]; FileStream fs = File.OpenRead(ap.filename); fs.Read(dat, 0, 44);//跳过文件头,wav文件头不一定是44字节,有些会更多,此演示程序不处理此差异。 while (true) { int datlen = fs.Read(dat, 0, 640); if (datlen >= 640) { IntPtr p = Marshal.UnsafeAddrOfPinnedArrayElement(dat, 0); Marshal.Copy(p, pcm, 0, pcm.Length); DeviceInterfaceDll.SR_EmergencyData(sHandle, pcm); offset += 640; } else { break; } this.Invoke(h, sHandle, "", false, (int)(100 * offset / fs.Length)); } } } finally { DeviceInterfaceDll.SR_EmergencyClose(sHandle, ap.userid); this.Invoke(h, sHandle, "", true, 0); EmergencyPlayThead = null; } }
private void Button1_Click(object sender, EventArgs e) { if (comboBox1.Text != null) { uint ret = DeviceInterfaceDll.SR_Login(comboBox1.Text, textBox1.Text, textBox2.Text); if (ret > 0) { //ListViewItem item = new ListViewItem(); ListViewItem item = listView1.Items.Add(""); item.SubItems.Add(ret.ToString()); item.SubItems.Add(comboBox1.Text); item.ImageIndex = 0;//white //MessageBox.Show(string.Format("{0:S} login is successful, userid = {1:D}", textBox1.Text, ret)); } else { MessageBox.Show(string.Format("{0:S} login is false, error = {1:D}", textBox1.Text, ret)); } } }
private void Button6_Click(object sender, EventArgs e) { if (comboBox2.Text == "") { MessageBox.Show("please select the user id first."); return; } uint id = Convert.ToUInt32(comboBox2.Text); for (int i = listView2.SelectedItems.Count - 1; i >= 0; i--) { ListViewItem ls = (ListViewItem)listView2.SelectedItems[i]; string filename = ls.SubItems[1].Text; uint ret = DeviceInterfaceDll.SR_DeleteFile(id, filename); if (ret == 0) { listView2.Items.Remove(ls); } } }
private void SDPlayFileThread(object obj) { ThreadParam ap = (ThreadParam)obj; Delegate h = new DelegateShowProcess(ShowProgress); uint ret = DeviceInterfaceDll.SR_PutFile(ap.id, ap.filename, ap.volume); if (ret == DeviceInterfaceDll.RC_OK) { try { while (true) { ret = DeviceInterfaceDll.SR_PutFileStatus(ap.id, out uint nProcess); if (ret == DeviceInterfaceDll.RC_OK) { int process = (int)nProcess; this.Invoke(h, process); } else { break; } Thread.Sleep(1000); } //this.Invoke(h, 101); } catch (ThreadAbortException e) { DeviceInterfaceDll.SR_PutFileClose(ap.id); } finally { this.Invoke(h, 101); dataThread = null; } } }
private void FilePlayThread(Object arg) { uint ret; ThreadParam ap = (ThreadParam)arg; WorkProcessHandler h = new WorkProcessHandler(FilePlayProcess); //ret = DeviceInterfaceDll.SR_UploadFile(out uint sHandle, ap.userid, ap.filename, DeviceInterfaceDll.UPLOAD_AUDIO_FILE_RELEASE, false); ret = DeviceInterfaceDll.SR_PlayFile(out uint sHandle, ap.userid, ap.filename, 97); if (ret == DeviceInterfaceDll.RC_OK) { try { int offset = 0; byte[] dat = new byte[1024]; FileStream fs = File.OpenRead(ap.filename); while (true) { int datlen = fs.Read(dat, 0, dat.Length); if (datlen > 0) { DeviceInterfaceDll.SR_PlayFileData(sHandle, dat, datlen); offset += datlen; } else { break; } this.Invoke(h, sHandle, "", false, (int)(100 * offset / fs.Length)); } } finally { DeviceInterfaceDll.SR_PlayFileClose(sHandle); this.Invoke(h, sHandle, "", true, 0); PlayThread = null; } } }
private void SDCardUploadFileThread(object obj) { ThreadParam ap = (ThreadParam)obj; Delegate h = new DelegateShowProcess(ShowProgress); uint ret = DeviceInterfaceDll.SR_UploadFile(out uint handle, ap.id, ap.filename, true); if (ret == DeviceInterfaceDll.RC_OK) { try { long count = 0; byte[] bdata = new byte[1024]; FileStream fs = File.OpenRead(ap.filename); if (fs != null) { int rlen; do { rlen = fs.Read(bdata, 0, bdata.Length); if (rlen > 0) { count += rlen; DeviceInterfaceDll.SR_UploadFileData(handle, bdata, rlen); this.Invoke(h, (int)(100 * count / fs.Length)); } }while (rlen >= bdata.Length); } } catch (ThreadAbortException e) { } finally { DeviceInterfaceDll.SR_UploadClose(handle); this.Invoke(h, 101); } } }
private void Form1_FormClosed(object sender, FormClosedEventArgs e) { DeviceInterfaceDll.SR_Cleanup(); }
private void IntercomThread(object obj) { short[] micpack = new short[2048]; int micpack_length = 0; short[] speakerpack = new short[2048]; int speakerpack_length = 0; AudioPowerUpdate handler = new AudioPowerUpdate(AudioPowerUpdateHandler); UInt32 h; ThreadParam ap = (ThreadParam)obj; uint ret = DeviceInterfaceDll.SR_VoiceCom(out h, ap.userid); if (ret == DeviceInterfaceDll.RC_OK) { int r = SoundCardDLL.SoundCardInit(16000); if (r == 0) { try { while (true) { micpack_length = 0; speakerpack_length = 0; if (SoundCardDLL.SoundCardWaitForInputData()) { while (true) { short[] pcmbuf = SoundCardDLL.SoundCardReadFrom(320); if (pcmbuf == null) { break; } if ((micpack_length + pcmbuf.Length) < 2048) { Array.Copy(pcmbuf, 0, micpack, micpack_length, pcmbuf.Length); micpack_length += pcmbuf.Length; } if (checkBox1.Checked) { Array.Clear(pcmbuf, 0, pcmbuf.Length); } short[] pcmbuf1 = DeviceInterfaceDll.SR_VoiceComData(h, pcmbuf); if (pcmbuf1 != null) { SoundCardDLL.SoundCardWriteTo(pcmbuf1); if ((speakerpack_length + pcmbuf1.Length) < 2048) { Array.Copy(pcmbuf1, 0, speakerpack, speakerpack_length, pcmbuf1.Length); speakerpack_length += pcmbuf1.Length; } } } } double mic_db = 0; double speaker_db = 0; if (micpack_length > 0) { double a = 0; for (int i = 0; i < micpack_length; i++) { a += micpack[i] * micpack[i]; } mic_db = 20 * Math.Log10(a / (dbBase * micpack_length)); mic_db += 100; if (mic_db < 0) { mic_db = 0; } if (mic_db > 100) { mic_db = 100; } this.Invoke(handler, Convert.ToInt32(mic_db), -1); } if (speakerpack_length > 0) { double a = 0; for (int i = 0; i < speakerpack_length; i++) { a += speakerpack[i] * speakerpack[i]; } speaker_db = 20 * Math.Log10(a / (dbBase * speakerpack_length)); speaker_db += 100; if (speaker_db < 0) { speaker_db = 0; } if (speaker_db > 100) { speaker_db = 100; } this.Invoke(handler, -1, Convert.ToInt32(speaker_db)); } } } finally { DeviceInterfaceDll.SR_VoiceComClose(h, ap.userid); SoundCardDLL.SoundCardClose(); dataThread = null; } } } }
private void UpdateThread(object obj) { //ThreadParam ap = (ThreadParam)obj; Delegate h = new DelegateShowProcess(ShowProcess); try { uint ret; if ((bin_filename != null) && (File.Exists(bin_filename))) { ret = DeviceInterfaceDll.SR_Update(out uint bin_handle, id, 0, bin_filename); if (ret == DeviceInterfaceDll.RC_OK) { try { int count = 0; byte[] bdata = new byte[1024]; FileStream fs = File.OpenRead(bin_filename); if (fs != null) { int rlen; do { rlen = fs.Read(bdata, 0, bdata.Length); if (rlen > 0) { count += rlen; DeviceInterfaceDll.SR_UpdateData(bin_handle, bdata, rlen); this.Invoke(h, bin_filename, (int)(100 * count / fs.Length)); } //System.Windows.Forms.Application.DoEvents(); }while (rlen >= bdata.Length); } fs.Close(); } finally { DeviceInterfaceDll.SR_UpdateClose(bin_handle); } } } Thread.Sleep(500); if ((pak_filename != null) && (File.Exists(pak_filename))) { ret = DeviceInterfaceDll.SR_Update(out uint pak_handle, id, 1, pak_filename); if (ret == DeviceInterfaceDll.RC_OK) { try { int count = 0; byte[] bdata = new byte[1024]; FileStream fs = File.OpenRead(pak_filename); if (fs != null) { int rlen; do { rlen = fs.Read(bdata, 0, bdata.Length); if (rlen > 0) { count += rlen; DeviceInterfaceDll.SR_UpdateData(pak_handle, bdata, rlen); this.Invoke(h, pak_filename, (int)(100 * count / fs.Length)); } }while (rlen >= bdata.Length); //wait update 200 } //else //{ // Thread.Sleep(0); //} fs.Close(); } finally { DeviceInterfaceDll.SR_UpdateClose(pak_handle); } } } DeviceInterfaceDll.SR_Apply(id); } finally { this.Invoke(h, "", 101); } }
private void UpdateThread(object obj) { ThreadParam ap = (ThreadParam)obj; Delegate h = new DelegateShowProcess(ShowProgress); try { uint ret; uint handle; ret = DeviceInterfaceDll.SR_Update(out handle, ap.id, 0, ap.bin_filename); if (ret == DeviceInterfaceDll.RC_OK) { try { int count = 0; byte[] bdata = new byte[1024]; FileStream fs = File.OpenRead(ap.bin_filename); if (fs != null) { int rlen; do { rlen = fs.Read(bdata, 0, bdata.Length); if (rlen > 0) { count += rlen; DeviceInterfaceDll.SR_UpdateData(handle, bdata, rlen); this.Invoke(h, ap.bin_filename, (int)(100 * count / fs.Length)); } }while (rlen >= bdata.Length); } } finally { DeviceInterfaceDll.SR_UpdateClose(handle); //this.Invoke(h, "", 101); } } ret = DeviceInterfaceDll.SR_Update(out uint pak_handle, ap.id, 1, ap.pak_filename); if (ret == DeviceInterfaceDll.RC_OK) { try { int count = 0; byte[] bdata = new byte[1024]; FileStream fs = File.OpenRead(ap.pak_filename); if (fs != null) { int rlen; do { rlen = fs.Read(bdata, 0, bdata.Length); if (rlen > 0) { count += rlen; DeviceInterfaceDll.SR_UpdateData(pak_handle, bdata, rlen); this.Invoke(h, ap.pak_filename, (int)(100 * count / fs.Length)); } }while (rlen >= bdata.Length); } } finally { DeviceInterfaceDll.SR_UpdateClose(handle); } } } finally { this.Invoke(h, "", 101); } }