Ik zal effe mijn programma posten. kwa opbouw ziet het er nog niet uit moet ik allemaal nog goed zetten.
/*================================================
================================================*/
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>
#include <string.h>
//#include "serial.h"
// Flow control flags
#define FC_DTRDSR 0x01
#define FC_RTSCTS 0x02
#define FC_XONXOFF 0x04
//#include <tarray.h>
using namespace std;
BOOL bPortReady;
DCB dcb;
COMMTIMEOUTS CommTimeouts;
BOOL bWriteRC;
BOOL bReadRC;
DWORD iBytesWritten;
DWORD iBytesRead;
HANDLE SerialInit(char *ComPortName, int BaudRate)
{
HANDLE hCom;
hCom = CreateFile(ComPortName,
GENERIC_READ | GENERIC_WRITE,
0, // exclusive access
NULL, // no security
OPEN_EXISTING,
0, // no overlapped I/O
NULL); // null template
bPortReady = SetupComm(hCom, 2, 128); // set buffer sizes
bPortReady = GetCommState(hCom, &dcb);
dcb.BaudRate = BaudRate;
dcb.ByteSize = 8;
dcb.Parity = NOPARITY;
//dcb.Parity = EVENPARITY;
dcb.StopBits = ONESTOPBIT;
dcb.fAbortOnError = TRUE;
// set XON/XOFF
dcb.fOutX = FALSE; // XON/XOFF off for transmit
dcb.fInX = FALSE; // XON/XOFF off for receive
// set RTSCTS
dcb.fOutxCtsFlow = false; // turn on CTS flow control
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; //
// set DSRDTR
dcb.fOutxDsrFlow = FALSE; // turn on DSR flow control
//dcb.fDtrControl = DTR_CONTROL_ENABLE; //
dcb.fDtrControl = DTR_CONTROL_DISABLE; //
// dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; //
bPortReady = SetCommState(hCom, &dcb);
// Communication timeouts are optional
bPortReady = GetCommTimeouts (hCom, &CommTimeouts);
CommTimeouts.ReadIntervalTimeout = 5000;
CommTimeouts.ReadTotalTimeoutConstant = 5000;
CommTimeouts.ReadTotalTimeoutMultiplier = 1000;
CommTimeouts.WriteTotalTimeoutConstant = 5000;
CommTimeouts.WriteTotalTimeoutMultiplier = 1000;
bPortReady = SetCommTimeouts (hCom, &CommTimeouts);
return hCom;
}
char SerialGetc(HANDLE *hCom)
{
char rxchar;
BOOL bReadRC;
static DWORD iBytesRead;
bReadRC = ReadFile(*hCom, &rxchar, 1, &iBytesRead, NULL);
return rxchar;
}
void SerialPutc(HANDLE *hCom, char txchar)
{
char bWriteRC;
static DWORD iBytesWritten;
bWriteRC = WriteFile(*hCom, &txchar, 1, &iBytesWritten,NULL);
return;
}
/*================================================= =====
Function to multiply matrix
================================================== ===*/
void mmult (int rows, int cols, int rows1, int cols1,int result, double m1[][4], double m2[][4], double m3[][4], double m4[][4], double m5[][4],double m6[][4], double m7[][4], double m8[][4], double m9[][4], double m10[][4],double mk1[][4])
{
double m11[4][4];//holds the result of A * B
double m12[4][4];//holds the result of AB * C
double m13[4][4];//holds the result of ABC * D
double m14[4][4];//holds the result of ABCD * E
double m15[4][4];//holds result of been 1
double m16[4][4];//holds the result of A * B
double m17[4][4];//holds the result of AB * C
double m18[4][4];//holds the result of ABC * D
double m19[4][4];//holds the result of ABCD * E
double m20[4][4];//holds result of been 2
double m21[4][4];//holds result of been totaal
{ //double result = mk1[0][0] - mk1[0][0];
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m1[k] * m2[k][j];
}
m11[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m11[k] * m3[k][j];
}
m12[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m12[k] * m4[k][j];
}
m13[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m13[k] * m5[k][j];
}
m14[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m14[k] * mk1[k][j];
}
m15[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m6[k] * m7[k][j];
}
m16[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m16[k] * m8[k][j];
}
m17[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m17[k] * m9[k][j];
}
m18[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m18[k] * m10[k][j];
}
m19[j] = val;
}
}
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
double val = 0;
for (int k=0; k<cols; k++)
{
val = val + m19[k] * mk1[k][j];
}
m20[j] = val;
}
{
result=m20[0][0] - m15[0][0];
}
}
{ cout<<result;
cout<<"\n";
}
//print matrix 11
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
cout<<" "<<m11[j];
}
cout<<"\n";
}
cout<<"\n";
//print matrix 12
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
cout<<" "<<m12[j];
}
cout<<"\n";
}
cout<<"\n";
//print matrix 13
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
cout<<" "<<m13[j];
}
cout<<"\n";
}
cout<<"\n";
//print matrix 14
for (int i=0; i<rows; i++)
{
for (int j=0; j<cols; j++)
{
cout<<" "<<m14[j];
}
cout<<"\n";
}
cout<<"\n";
//print matrix 15
for (int i=0; i<rows1; i++)
{
for (int j=0; j<cols1; j++)
{
cout<<" "<<m15[j];
}
cout<<"\n";
}
cout<<"\n";
//print matrix 15
for (int i=0; i<rows1; i++)
{
for (int j=0; j<cols1; j++)
{
cout<<" "<<m20[j];
}
cout<<"\n";
}
cout<<"\n";
}
//Function declarations
void mmult(int,int,int,int,int,double[][4],double[][4],double[][4],double[][4],double[][4],double[][4],double[][4],double[][4],double[][4],double[][4],double[][4]);
int main()
{
double a;
double b;
double c;
double d;
double e;
double f;
double g;
double h;
double i;
double j;
//double result;
int stuur;
cout<<"geef waarde in voor a";
cin >> a;
cout<< endl;
cout<<"geef waarde in voor b";
cin >> b;
cout<< endl;
cout<<"geef waarde in voor c";
cin >> c;
cout<< endl;
cout<<"geef waarde in voor d";
cin >> d;
cout<< endl;
cout<<"geef waarde in voor e";
cin >> e;
cout<< endl;
cout<<"geef waarde in voor f";
cin >> f;
cout<< endl;
cout<<"geef waarde in voor g";
cin >> g;
cout<< endl;
cout<<"geef waarde in voor h";
cin >> h;
cout<< endl;
cout<<"geef waarde in voor i";
cin >> i;
cout<< endl;
cout<<"geef waarde in voor j";
cin >> j;
cout<< endl;
//Hard code matrix A
double m1[4][4] = {{(cos(a)),0,(-sin(a)),0},
{0,1,0,0},
{(sin(a)),0,(cos(a)),0},
{0,0,0,1}};
//Hard code matrix B
double m2[4][4] = {{cos(b),-sin(b),0,(1-cos(b))*42.7},
{sin(b),cos(b),0,(-sin(b))*42.70},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix C
double m3[4][4] = {{cos(c),-sin(c),0,(1-cos(c))*(42.7+57.2)},
{sin(c),cos(c),0,(-sin(c))*(42.7+57.2)},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix D
double m4[4][4] = {{cos(d),-sin(d),0,(1-cos(d))*(42.7+57.2+42.7)},
{sin(d),cos(d),0,(-sin(d))*(42.7+57.2+42.7)},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix E
double m5[4][4] = {{cos(e),0,-sin(e),(1-cos(e))*(42.7+57.2+42.7+42.7)},
{0,1,0,0},
{sin(e),0,cos(e),(-sin(e))*(42.7+57.2+42.7+42.7)},
{0,0,0,1}};
//Hard code matrix f
double m6[4][4] = {{(cos(f)),0,(-sin(f)),0},
{0,1,0,0},
{(sin(f)),0,(cos(f)),0},
{0,0,0,1}};
//Hard code matrix g
double m7[4][4] = {{cos(g),-sin(g),0,(1-cos(g))*42.7},
{sin(g),cos(g),0,(-sin(g))*42.70},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix h
double m8[4][4] = {{cos(h),-sin(h),0,(1-cos(h))*(42.7+57.2)},
{sin(h),cos(h),0,(-sin(h))*(42.7+57.2)},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix i
double m9[4][4] = {{cos(i),-sin(i),0,(1-cos(i))*(42.7+57.2+42.7)},
{sin(i),cos(i),0,(-sin(i))*(42.7+57.2+42.7)},
{0,0,1,0},
{0,0,0,1}};
//Hard code matrix j
double m10[4][4] = {{cos(j),0,-sin(j),(1-cos(j))*(42.7+57.2+42.7+42.7)},
{0,1,0,0},
{sin(j),0,cos(j),(-sin(j))*(42.7+57.2+42.7+42.7)},
{0,0,0,1}};
double mk1[4][4] = {{228},
{0},
{0},
{1}};
int result();
//call function
mmult(4,4,4,1,result,m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,mk1);
//Where '3' is the maximum number of rows in either
//matrix A or B
//and '4' is the maximun number of columns in either
//matrix A or B
if (result >= 0 && result <= 10 )
{
stuur=49;
}
if (result > 10 && result <= 20 )
{
stuur=50;
}
if (result > 20 && result <= 30 )
{
stuur=51;
}
if (result >= -10 && result <= 0 )
{
stuur=49;
}
if (result > -20 && result <= -10 )
{
stuur=50;
}
if (result > -30 && result <= -20 )
{
stuur=51;
}
{
HANDLE my=SerialInit("com1",9600);
char letter;
HANDLE *ptr;
ptr = &my;
SerialPutc(ptr,stuur);
letter=SerialGetc(ptr);
cout<<stuur;
cout<<"\n";
cout << "Gestuurd is: ";
cout << letter;
cout<<"\n";
cout << result;
}
cin.get();
cin.get();
return 0;
}
Het gaat om de functie result!!!