• Content count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About da_cobra

  • Rank
  1. c# : trimming a string

    I'm trying to get a new string with only some characters (in my case only numbers) So if I have the following string "hello 123 goodbye!" I should get : "123" and I thought the solution was first remove all the numbers "1234567890" so then I get : "hello goodbye" and then I remove "hello goodbye" from "hello 123 goodbye" => "123" But it seems I will have to write my own function for this :(
  2. c# : trimming a string

    I have a string with for example : "ABCDEFGHI" And I want to get a new string which has only the letters "AEI" So I do this : string list = "AEI"; string temp1; temp1 = temp.Trim(list.ToCharArray()); // first remove "AEI" temp = temp.Trim(temp1.ToCharArray()); // then remove "BCDFGH" from the first string But this code doesn't work. When I debug this temp1 still contains "ABCDEFGHI" Am I missing something here?!? :(
  3. serial communication in C#

    yeah, I know it's weird, but I tried "\n" and "\r" and that didn't work, but "\r\n" did, so.... :D
  4. serial communication in C#

    I found my problem : A carriage return is "\r\n"
  5. I'm trying to communicate with a digital voltmeter through IR communication which failes for now : All I have is this document : specification for Fluke 189 Voltmeter I can open my connection : SerialPort sp = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One); // open serial port sp.Open(); // set read time out to 500 ms sp.ReadTimeout = 500; Sending works, without any errors, but when I try to receive I get a timeout error. private void btnGetID_Click(object sender, EventArgs e) { try { //write line to serial port //sp.WriteLine(txtText.Text); sp.WriteLine("ID\r"); //clear the text box txtText.Text = ""; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } try { //clear the text box txtTextReceive.Text = ""; //read serial port and displayed the data in text box txtTextReceive.Text = sp.ReadLine(); } catch (System.Exception ex) { MessageBox.Show(ex.Message); } } I'm 100% sure that the cable and the settings are correct, because I have an official application that can connect to my Voltmeter on the COM3 port with those settings. Maybe it has something to do with the carriage return? => <CR> or \r ?!? I hope someone can help me out here. Thanx in advance...
  6. adding to a xml-file

    Damn, I'm very sorry that I didn't say which language I'd used. It's indeed C#. I'll try your advise asap. thx for replying! edit : Both solutions worked for me, but I used dalep's solution, because it's shorter and easier, but still thx alot for helping me out, both!
  7. I want this : [source <?xml version="1.0" encoding="UTF-8"?> <Highscore> <Line> <Name>Da_cobra</Name> <Score>9500</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>9000</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>8500</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>8000</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>7500</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>7000</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>6500</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>6000</Score> </Line> <Line> <Name>Da_cobra</Name> <Score>5500</Score> </Line> </Highscore> but I have this : <?xml version="1.0" encoding="UTF-8"?> <Highscore> <Line> <Name>Da_cobraDa_cobraDa_cobraDa_cobraDa_cobraDa_cobraDa_cobraDa_cobraDa_cobra</Name> <Score>950090008500800075007000650060005500</Score> </Line> </Highscore> with this code : XmlNode root = xmlDoc.DocumentElement; XmlText textNode ; XmlElement lineNode = xmlDoc.CreateElement("Line"); XmlElement nameNode = xmlDoc.CreateElement("Name"); XmlElement scoreNode = xmlDoc.CreateElement("Score"); for (int iCounter = 0; iCounter < 10; iCounter++) { textNode = xmlDoc.CreateTextNode(strDefaultName); root.AppendChild(lineNode); lineNode.AppendChild(nameNode); nameNode.AppendChild(textNode); textNode = xmlDoc.CreateTextNode((lDefaultScore - (iCounter * lLowerScore)).ToString()); lineNode.AppendChild(scoreNode); scoreNode.AppendChild(textNode); } As you can see I should have 10 child nodes "lines" with 2 child nodes in it "name" and "score" I only have 9 "lines" nodes (least of my problems for now), but somehow with my code all the names are put behind each other and also all the scores?!? what am I doing wrong?
  8. C# using structs

    that's it indeed, thx!
  9. Hello, I'm rather new to the C# language, but I know C++. Now I came upon a problem when using a struct and I can't seem to figure it out for the moment : I want to create a highscore table (I just started writing the code, so I do not have much for now). public int NewHighscoreTable(string strDefaultName, long lDefaultScore, long lDefaultLowerScore) { FileStream fs = File.Create("highscore.dat"); struct highscoreLine { public string strName; public int iScore; } highscoreLine hl = new highscoreLine(); return 0; } When I execute this code I get the following errors : Error 1 } expected => points to the semicolon (;) right after the FileStream line Error 2 Invalid token 'return' in class, struct, or interface member declaration Error 3 Type or namespace definition, or end-of-file expected When I comment out the whole struct lines, then the errors are gone and I can execute my code with no problem. Am I missing something here?!?
  10. thx for the reply : first of all the : Indeed eventually I would make a function that can send a string, but since my application for now is just for trying I thought I would send the commands byte at a time. Second : The infra red cable is brand new and the multimeter also, so I don't think there is a problem there. But the infra red cable isn't of the same brand as the multimeter. Do you think that could make a difference? Third : I'm sending the commands first, because that seems to be the easiest route , because if the communication works, the backlight of my multimeter would jump on. If I send the DS command, I would also have to try to receive from the multimeter. Which is a little bit more coding for me, without knowing if I do the receiving correct.
  11. Hello, I'm trying to communicate with my multimeter (fluke 189) through IR. I have an IR cable (which came with my TV-card) which is connected on my serial port com1. I followed the instructions on http://www.codeguru.com/Cpp/I-N/network/serialcommunications/article.php/c5395/ and I have the specifications for the communication here : http://www.cfa.harvard.edu/~thunter/manuals/RemoteSpec89_18X.htm but it doesn't work (probably because I did something wrong, offcourse) here's the code : bool CFlukeDlg::ConfigurePort(DWORD BaudRate, BYTE ByteSize, DWORD fParity, BYTE Parity, BYTE StopBits) { if ((m_bPortReady = GetCommState(m_hComm, &m_dcb))==0) { MessageBox("GetCommState Error","Error",MB_OK+MB_ICONERROR) ; CloseHandle(m_hComm) ; return false ; } m_dcb.BaudRate =BaudRate ; m_dcb.ByteSize = ByteSize ; m_dcb.Parity =Parity ; m_dcb.StopBits =StopBits ; m_dcb.fBinary=TRUE ; m_dcb.fDsrSensitivity=false ; m_dcb.fParity=fParity ; m_dcb.fOutX=false ; m_dcb.fInX=false ; m_dcb.fNull=false ; m_dcb.fAbortOnError=TRUE ; m_dcb.fOutxCtsFlow=FALSE ; m_dcb.fOutxDsrFlow=false ; m_dcb.fDtrControl=DTR_CONTROL_DISABLE ; m_dcb.fDsrSensitivity=false ; m_dcb.fRtsControl=RTS_CONTROL_DISABLE ; m_dcb.fOutxCtsFlow=false ; m_dcb.fOutxCtsFlow=false ; m_bPortReady = SetCommState(m_hComm, &m_dcb) ; if (m_bPortReady ==0) { MessageBox("SetCommState Error","Error",MB_OK+MB_ICONERROR) ; CloseHandle(m_hComm) ; return false ; } return true ; } bool CFlukeDlg::SetCommunicationTimeouts(DWORD ReadIntervalTimeout, DWORD ReadTotalTimeoutMultiplier, DWORD ReadTotalTimeoutConstant, DWORD WriteTotalTimeoutMultiplier, DWORD WriteTotalTimeoutConstant) { if ((m_bPortReady = GetCommTimeouts (m_hComm, &m_CommTimeouts))==0) return false ; m_CommTimeouts.ReadIntervalTimeout = ReadIntervalTimeout ; m_CommTimeouts.ReadTotalTimeoutConstant = ReadTotalTimeoutConstant ; m_CommTimeouts.ReadTotalTimeoutMultiplier = ReadTotalTimeoutMultiplier ; m_CommTimeouts.WriteTotalTimeoutConstant = WriteTotalTimeoutConstant ; m_CommTimeouts.WriteTotalTimeoutMultiplier = WriteTotalTimeoutMultiplier ; m_bPortReady = SetCommTimeouts (m_hComm, &m_CommTimeouts) ; if (m_bPortReady ==0) { MessageBox("StCommTimeouts function failed","Com Port Error", MB_OK+MB_ICONERROR) ; CloseHandle(m_hComm) ; return false ; } return true ; } bool CFlukeDlg::WriteByte(BYTE bybyte) { iBytesWritten=0 ; if (WriteFile(m_hComm,&bybyte,1,&iBytesWritten,NULL)==0) return false ; else return true ; } bool CFlukeDlg::ReadByte(BYTE &resp) { BYTE rx ; resp=0 ; DWORD dwBytesTransferred=0 ; if (ReadFile(m_hComm, &rx, 1, &dwBytesTransferred, 0)) { if (dwBytesTransferred == 1) { resp=rx ; return true ; } } return false ; } void CFlukeDlg::ClosePort() { CloseHandle(m_hComm) ; return ; } I have 3 buttons on my form with the following functions : void CFlukeDlg::OnOpenport() { // TODO: Add your control notification handler code here if (!OpenPort("com1")) { MessageBox("Failed to open the serial port : com1") ; } else { MessageBox("Serial port com1 open for communication, now configuring...") ; ConfigurePort(CBR_9600, 8, true, NOPARITY , ONESTOPBIT ) ; SetCommunicationTimeouts(0,500,0,0,0) ; MessageBox("Serial port com1 configured!") ; } } void CFlukeDlg::OnCloseport() { // TODO: Add your control notification handler code here ClosePort() ; MessageBox("Serial port com1, closed!") ; } void CFlukeDlg::OnBacklight() { // TODO: Add your control notification handler code here MessageBox("Backlight on!") ; if (!WriteByte('S')) MessageBox("Failed to write to serial port!") ; if (!WriteByte('F')) MessageBox("Failed to write to serial port!") ; if (!WriteByte(' ')) MessageBox("Failed to write to serial port!") ; if (!WriteByte('1')) MessageBox("Failed to write to serial port!") ; if (!WriteByte('9')) MessageBox("Failed to write to serial port!") ; if (!WriteByte('\n')) MessageBox("Failed to write to serial port!") ; } When I run the code, everything compiles fine. I can open the serial port com1, when I press the button "Open port" (=OnOpenPort()) But when I press the button Backlight on (=OnBacklight()) nothing happens. Backlight on = "SF 19 <CR>" (see specifications) My question is am I writing the correct way to the serial port in OnBacklight()? If so, what else could be the problem? Thanx in advance if there is any1 that could help me...
  12. problems with surfaces

    thx jollyjeffers, I used debugged my application (through your link in your signature) and I got these errors : Direct3D8: (ERROR) :This format is not supported for CreateImageSurface Direct3D8: (ERROR) :Failure trying to create image surface Direct3D8: (ERROR) :NULL surface interface specified. CopyRect fails So what exactly is wrong? And how can I fix it?
  13. problems with surfaces

    Hmmmm, as you can see, there is no camera/view. Could this be the part that's missing?
  14. Hello, I'm currently reading the book "game programming all in one" and I've stuck on a problem. Although I did everything that was written in the book and although everything compiles right, I still do not get what I should get . With the following code I should get a certain grey pattern on the top left of my window : Code: /* Initializes Direct3D */ HRESULT D3DWindow::SetupDirect3D(void) { /* Create the Direct3D object */ if (NULL == (m_pD3D = Direct3DCreate8(D3D_SDK_VERSION))) { return E_FAIL ; } /* Get the current display mode so we can know what bitdepth we are */ D3DDISPLAYMODE d3ddm; if (FAILED(m_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,&d3ddm))) { return E_FAIL ; } /* Fill in the present parameters */ D3DPRESENT_PARAMETERS d3dpp ; ZeroMemory(&d3dpp, sizeof(d3dpp)) ; /* We want windowed mode */ d3dpp.Windowed = TRUE ; /* Discard this */ d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD ; /* Same format as the current format (we got this from g_pD3D->GetAdapterDisplayMode) */ d3dpp.BackBufferFormat = d3ddm.Format ; /* Create the device */ if (FAILED(m_pD3D->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL, m_hWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &m_pD3DDevice))) { return E_FAIL ; } /* Create the surface */ if (FAILED(m_pD3DDevice->CreateImageSurface(256, 256, (D3DFORMAT) m_iD3DFormat, &m_pD3DSurface))) { return E_FAIL ; } /* Lock surface */ D3DLOCKED_RECT kLockedRect ; m_pD3DSurface->LockRect(&kLockedRect, NULL, 0) ; /* Cast a pointer to point to the first pixel */ DWORD *piSurfaceBuffer = (DWORD *)kLockedRect.pBits ; /* Fill surface */ int iX, iY ; for (iY=0; iY<256; iY++) { for (iX=0; iX<256; iX++) { /* Form a pattern */ int iPower = (int)(sin (iY * iX) * 128 + cos (iY * -iX) * 128) ; piSurfaceBuffer[iX + iY* (kLockedRect.Pitch >> 2)] = D3DCOLOR_XRGB (iPower, iPower, iPower) ; } } /* Unlock */ m_pD3DSurface->UnlockRect(); return D3D_OK ; } mrBool32 D3DWindow::Frame(void) { /* Clear the window to blue */ m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0) ; /* Get back buffer */ LPDIRECT3DSURFACE8 pBackBuffer ; m_pD3DDevice->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer) ; /* Start rendering */ m_pD3DDevice->BeginScene() ; /* Copy the surface to the screen */ m_pD3DDevice->CopyRects(m_pD3DSurface, NULL, 0, pBackBuffer, NULL) ; m_pD3DDevice->EndScene() ; /* Present the rendered scene to the screen */ m_pD3DDevice->Present(NULL, NULL, NULL, NULL) ; return mrTrue ; } The function setupDirect3D is (obviously) only runned once. The function frame is runned continueously. Everything compiles with no errors and D3D is initialized right, because I do get the blue background that I ask for in the frame() function. Does any1 see something wrong with this code?
  15. Project Ideas

    I personally think a tetris game or breakout clone is the simplest project you can start with...